NAME
DELETE - 删除一个表中的行
SYNOPSIS
DELETE FROM [ ONLY ] table [ WHERE condition ]
DESCRIPTION 描述
DELETE 从指明的表里删除满足 WHERE 子句的行。 如果 WHERE 子句不存在, 效果是删除表中所有行。结果是一个有效的空表。
- Tip: 提示: TRUNCATE [truncate(7)] 是一个 PostgreSQL 扩展, 它提供一个更快的从表中删除所有行的机制。
缺省时 DELETE 将删除所声明的表和所有它的子表的记录。 如果你希望只更新提到的表,你应该使用 ONLY 子句。
要对表进行删除,你必须对它有 DELETE 权限,同样也必须有 SELECT 的权限,这样才能对符合 condition 的值进行读取操作。
PARAMETERS 参数
- table
一个现存表的名字(可以有模式修饰)。- condition
一个返回 boolean 类型值的值表达式,它判断哪些行需要被删除。
OUTPUTS 输出
成功时,DELETE 命令返回形如
DELETE count
的标签。 count 是被删除的行数。 如果 count 为 0,没有行匹配 condition (这个不认为是错误)。
EXAMPLES 例子
删除所有电影(films)但不删除音乐(musicals):
DELETE FROM films WHERE kind <> 'Musical';
清空表 films:
DELETE FROM films;
#p#
NAME
DELETE - delete rows of a table
SYNOPSIS
DELETE FROM [ ONLY ] table [ WHERE condition ]
DESCRIPTION
DELETE deletes rows that satisfy the WHERE clause from the specified table. If the WHERE clause is absent, the effect is to delete all rows in the table. The result is a valid, but empty table.
- Tip: TRUNCATE [truncate(7)] is a PostgreSQL extension which provides a faster mechanism to remove all rows from a table.
By default, DELETE will delete rows in the specified table and all its subtables. If you wish to only delete from the specific table mentioned, you must use the ONLY clause.
You must have the DELETE privilege on the table to delete from it, as well as the SELECT privilege for any table whose values are read in the condition.
PARAMETERS
- table
- The name (optionally schema-qualified) of an existing table.
- condition
- A value expression that returns a value of type boolean that determines the rows which are to be deleted.
OUTPUTS
On successful completion, a DELETE command returns a command tag of the form
DELETE count
The count is the number of rows deleted. If count is 0, no rows matched the condition (this is not considered an error).
EXAMPLES
Delete all films but musicals:
DELETE FROM films WHERE kind <> 'Musical';
Clear the table films:
DELETE FROM films;