For faster navigation, this Iframe is preloading the Wikiwand page for DELETE (SQL).

DELETE (SQL)

DELETE(デリート)ステートメントは、1つもしくは複数のレコードを削除する、SQLにおけるデータ操作言語 (DML)ステートメントの1つである。すべてのレコードを一括削除するかまたは、条件式を満たす一部のレコードだけを削除することができる。

構文

[編集]
 DELETE FROM 主表 [WHERE 条件式]

WHERE句で条件式を指定した場合は、条件式に一致するレコードのみ削除される。WHERE句が省略された場合は、全レコードが削除される。

DELETE の際に削除の対象以外の表を参照する場合には副問い合わせを使う必要があるが、データベースによっては USING または追加の FROM 句により表の参照を追加できるものもある。 [1] [2] [3]

 DELETE FROM 主表 USING 副表 WHERE 主表. = 副表. ...

DELETEステートメントを実行したとき、データベーストリガを設定することにより他のテーブルもあわせて削除することができる。例えば、2つのテーブルが外部キーでリンクされているとき、一方のテーブルのある行が削除されたなら、削除された行とリンクしている他方のテーブルの行もトリガーにより自動削除されることにより、参照整合性を維持することができる。

性能

[編集]

一般に、全ての行を削除する場合には DELETE よりも TRUNCATE TABLE ステートメントのほうが高速に処理できる。

サンプル

[編集]

テーブル pies から、項目 flavour が 'Lemon Meringue' である行を削除する:

 DELETE FROM pies WHERE flavour='Lemon Meringue';

テーブル mytable から、項目 mycol の値が100より大きい行を削除する:

DELETE FROM mytable WHERE mycol > 100;

テーブル mytable のすべての行を削除する:

DELETE FROM mytable;

脚注

[編集]
  1. ^ DELETE”. PostgreSQL 文書. 2009年9月23日閲覧。
  2. ^ DELETE Syntax”. MySQL 5.1 Reference Manual. 2014年12月8日閲覧。
  3. ^ DELETE (Transact-SQL)”. SQL Server 2008 オンライン ブック. 2009年9月23日閲覧。
{{bottomLinkPreText}} {{bottomLinkText}}
DELETE (SQL)
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?