|
DELETE描述DELETE 从指明的表里删除满足 WHERE condition (条件)的行. 如果 condition (WHERE 子句)不存在, 效果是删除表中所有行.结果是一个有效的空表.
缺省时DELETE将删除所声明的表和所有它的子表的记录. 如果你希望只更新提到的表,你应该使用OLNY子句. 要对表进行修改,你必须有写权限,同样也必须有读表的权限,这样才能对符合 condition(条件) 的值进行读取操作. 用法删除所有电影(films)但不删除音乐(musicals): 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)
|