如果 condition (WHERE 子句)不存在,效果是删除表中所有行.结果是一个有效的空表.
小技巧: TRUNCATE 是一个 Postgres 扩展,它提供一个更快的从表中删除所有行的机制。
DELETE FROM films WHERE kind <> 'Musical'; SELECT * FROM films; code | title | did | date_prod | kind | len -------+---------------------------+-----+------------+---------+------- UA501 | West Side Story | 105 | 1961-01-03 | Musical | 02:32 TC901 | The King and I | 109 | 1956-08-11 | Musical | 02:13 WD101 | Bed Knobs and Broomsticks | 111 | | Musical | 01:57 (3 rows)清空表 films:
DELETE FROM films; SELECT * FROM films; code | title | did | date_prod | kind | len ------+-------+-----+-----------+------+----- (0 rows)