DELETE
Deletes rows from a table.
Syntax
DELETE FROM [ONLY] <table> [[AS] <alias>]
[WHERE <condition> ]
Description
DELETE
deletes rows that satisfy the WHERE
clause from the specified table. If the WHERE
clause is absent, the effect is to delete all rows in the table. The result is a valid, but empty table.
By default, DELETE
will delete rows in the specified table and all its child tables. If you wish to delete only from the specific table mentioned, you must use the ONLY
clause.
You can use sub-selects to delete rows in a table using information contained in other tables in the database.
You must have the DELETE
privilege on the table to delete from it.
As the default, Relyt acquires an EXCLUSIVE
lock on tables for DELETE
operations on heap tables.
Parameters
-
ONLY
If specified, delete rows from the named table only. When not specified, any tables inheriting from the named table are also processed.
-
<table>
The name of an existing table. You can specify the name with the schema qualification.
-
<alias>
A substitute name for the target table. When an alias is provided, it completely hides the actual name of the table. For example, given
DELETE FROM foo AS f
, the remainder of theDELETE
statement must refer to this table asf
notfoo
. -
<condition>
An expression returning a value of type
boolean
, which determines the rows that are to be deleted.
Outputs
On successful completion, a DELETE
command returns a command tag of the form
DELETE <count>
The <count>
is the number of rows deleted. If count is 0, no rows were deleted by the query (this is not considered an error).
Examples
Delete all films but musicals:
DELETE FROM films WHERE kind <> 'Musical';
Clear the table films
:
DELETE FROM films;
SQL standard compatibility
This command conforms to the SQL standard.