0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[備忘録]SQLクエリまとめ④

0
Posted at

今回は、データの挿入、更新、削除に関することのみを紹介します。

INSERT

  • テーブルにレコードを挿入する
  • INSERT INTO テーブル名(カラム名) VALUES(値)
studentsテーブルにレコードを追加
INSERT INTO students(name, course)
VALUES("テスト太郎", "Ruby");

UPDATE

  • データを更新
  • UPDATE テーブル名 SET カラムを指定して値を代入 WHERE 更新するレコードのid
studentsテーブルのデータを更新
UPDATE students
SET name = "ほげ美", cource = "Go"
WHERE id = 5;

DELETE

  • レコードを削除
  • DELETE FROM テーブル名 WHERE 削除するレコードのid
idが10のレコードを削除
DELETE FROM students
WHERE id = 10;

まとめ

データの更新、削除はWHEREで指定しないと、全てのレコードを更新、削除してしまうので、注意!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?