PostgreSQL DELETE Query
PostgreSQL DELETE Query is used to delete one or more rows of a table. In DELETE query, you can also use clauses like WHERE, LIKE, IN, NOT IN, etc., to select the rows for which the DELETE operation will be performed.
The syntax of DELETE query is;
DELETE FROM table_name WHERE condition;
The use of WHERE clause is optional.
If you do not provide any selection criteria for the rows, then all the rows of the table would be deleted.
PostgreSQL DELETE One Row
We will start this example, where we will delete only one row. For this, we need to prepare WHERE clause which selects only one row.
Consider the following students table.
The following DELETE query will delete the row where
DELETE FROM students WHERE id=3;
Now, we will check the rows of the table.
PostgreSQL DELETE all rows of Table
Now we will delete all the rows of students table. Following would be the query to delete all rows of table. You have to exercise caution while running this query, because once all rows are deleted, they would be deleted permanently.
DELETE FROM students;
Let us see the contents of the table.
All the rows have been deleted.
In this PostgreSQL Tutorial, we deleted one or multiple or all rows of a table using PostgreSQL DELETE query.