DELETE

Name

DELETE  --  Deletes rows from a table テーブルから行を削除する。

Synopsis

DELETE FROM table [ WHERE condition ]
  

入力

table

The name of an existing table.

既存のテーブル名。

condition

This is an SQL selection query which returns the rows which are to be deleted.

削除すべき行を返す、SQL の選択問い合わせです。

Refer to the SELECT statement for further description of the WHERE clause.

WHERE 句についてのより詳細については、SELECT 文を参照して下さい。

出力

DELETE count

Message returned if items are successfully deleted. The count is the number of rows deleted.

各行が正常に削除された時に返されるメッセージです。 count は削除された 行数を示します。

If count is 0, no rows were deleted.

count が 0 の場合、 行が削除されなかったことを示します。

説明

DELETE removes rows which satisfy the WHERE clause from the specified table.

DELETE は指定したテーブルから WHERE 句を満たす 行を削除します。

If the condition (WHERE clause) is absent, the effect is to delete all rows in the table. The result is a valid, but empty table.

もし、condition (WHERE 句) がなければ、指定 テーブルの全ての行を削除することになります。 その結果、テーブルは有効のまま空になります。

You must have write access to the table in order to modify it, as well as read access to any table whose values are read in the condition.

テーブルを変更するために書き込み権限が必要です。同様に condition 内で指定した 値を持つテーブルへの読み込み権限も必要になります。

使用方法

Remove all films but musicals:

films テーブルから musicals 以外を全て削除します。

DELETE FROM films WHERE kind <> 'Musical';
SELECT * FROM films;

code |title                    |did| date_prod|kind      |len
-----+-------------------------+---+----------+----------+------
UA501|West Side Story          |105|1961-01-03|Musical   | 02:32
TC901|The King and I           |109|1956-08-11|Musical   | 02:13
WD101|Bed Knobs and Broomsticks|111|          |Musical   | 01:57
(3 rows)
   

Clear the table films:

films テーブルをクリアします。

DELETE FROM films;
SELECT * FROM films;

code|title|did|date_prod|kind|len
----+-----+---+---------+----+---
(0 rows)
   

互換性

SQL92

SQL92 allows a positioned DELETE statement:

SQL92 では、位置による DELETE 文が可能です。

DELETE FROM table WHERE
    CURRENT OF cursor
    
where cursor identifies an open cursor. Interactive cursors in Postgres are read-only. ここで、cursor はオープ ン済みのカーソルの識別子です。 Postgres の対話式カーソルは読み取り専用です。