PostgreSQL DELETE
The DELETE Statement
TheDELETE statement is used to delete existing records in a table.
Note: Be careful when deleting records in a table!Notice theWHERE clause in theDELETE statement.TheWHERE clause specifies which record(s) should be deleted.
If you omit theWHERE clause,
all records in the table will be deleted!.
To delete the record(s) where brand is 'Volvo', use this statement:
Example
Delete all records where brand is 'Volvo':
WHERE brand = 'Volvo';
Result
Which means that1 row was deleted.
Display Table
To check the result we can display the table with this SQL statement:
Delete All Records
It is possible to delete all rows in a table without deleting the table.This means that the table structure, attributes, and indexes will be intact.
The following SQL statement deletes all rows in thecarstable, without deleting the table:
Example
Delete all records in thecars table:
Result
Which means that all3 rows were deleted.
Display Table
To check the result we can display the table with this SQL statement:
TRUNCATE TABLE
Because we omit theWHERE clause in theDELETE statement above, all records will be deleted from the cars table.
The same would have been achieved by using theTRUNCATE TABLE statement:
Example
Delete all records in thecars table:
Result
Display Table
To check the result we can display the table with this SQL statement:

