DELETE
SQL - Language Statements
DELETE
Deletes rows from a table
1998-04-15
DELETE FROM table [ WHERE condition ]
1998-04-15
Inputs
table
The name of an existing table.
condition
This is an SQL selection query which returns the rows which
are to be deleted.
Refer to the SELECT statement for further description
of the WHERE clause.
1998-04-15
Outputs
DELETE count
Message returned if items are successfully deleted. The
count is the number
of rows deleted.
If count is 0,
no rows are deleted.
1998-04-15
Description
DELETE removes rows which satisfy the WHERE condition,
from the specified table.
If the condition is absent,
the effect is to delete all rows in the table.
The result is a valid, but empty table.
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.
Usage
Remove all films but 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
Clear the table films:
DELETE FROM films;
SELECT * FROM films;
code|title|did|date_prod|kind|len
----+-----+---+---------+----+---
(0 rows)
Compatibility
1998-04-15
SQL92
SQL92 defines a different syntax for a positioned DELETE statement:
DELETE FROM table WHERE CURRENT OF cursor
where cursor identifies an open cursor.