PostgreSQL DELETE Query
The DELETE command allows to empty the table or remove some partial records from the table.You can use the WHERE clause with the DELETE query to delete the selected rows.
PostgreSQL DELETE Syntax:
The syntax is as follows:
DELETE FROM table_name [WHERE condition]
In this, records that satisfying the WHERE condition are to be deleted.If there is no WHERE condition then all records are deleted from the table.The delete statement returns the number of deleted records. 0 if no record is deleted.
DELETE Example :
Consider the STUDENT table is having the following records
The following is an example, which would delete record for a student, whose ID is 2.
lfcdb=# DELETE FROM STUDENT WHERE ID = 2;
All the above statements would create the following records in STUDENT table
The following is an example, if you want to DELETE all the records from STUDENT table.
lfcdb=# DELETE FROM STUDENT;There is no record in the student table because all records have been deleted by the DELETE statement.