例子
# select * from COMPANY;
id | name | age | address | salary
----+-------+-----+-----------+--------
1 | Paul | 32 | California| 20000
2 | Allen | 25 | Texas | 15000
3 | Teddy | 23 | Norway | 20000
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
6 | Kim | 22 | South-Hall| 45000
7 | James | 24 | Houston | 10000
(7 rows)
以下是一个示例,它将删除 ID 为 7 的客户 -
testdb=# DELETE FROM COMPANY WHERE ID = 2;
现在,COMPANY 表将有以下记录 -
id | name | age | address | salary
----+-------+-----+-------------+--------
1 | Paul | 32 | California | 20000
3 | Teddy | 23 | Norway | 20000
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
6 | Kim | 22 | South-Hall | 45000
7 | James | 24 | Houston | 10000
(6 rows)
如果要删除 COMPANY 表中的所有记录,则不需要将 WHERE 子句与 DELETE 查询一起使用,如下所示 -
testdb=# DELETE FROM COMPANY;
现在,COMPANY 表没有任何记录,因为所有记录都已被 DELETE 语句删除。