DELETE 中文man頁面
NAME
DELETE - 刪除一個表中的行
SYNOPSIS
DELETE FROM [ ONLY ] table [ WHERE condition ]
DESCRIPTION 描述
DELETE 從指明的表里刪除滿足 WHERE 子句的行。 如果 WHERE 子句不存在, 效果是刪除表中所有行。結(jié)果是一個有效的空表。
- Tip: 提示: TRUNCATE [truncate(7)] 是一個 PostgreSQL 擴展, 它提供一個更快的從表中刪除所有行的機制。
缺省時 DELETE 將刪除所聲明的表和所有它的子表的記錄。 如果你希望只更新提到的表,你應(yīng)該使用 ONLY 子句。
要對表進行刪除,你必須對它有 DELETE 權(quán)限,同樣也必須有 SELECT 的權(quán)限,這樣才能對符合 condition 的值進行讀取操作。
PARAMETERS 參數(shù)
- table
一個現(xiàn)存表的名字(可以有模式修飾)。- condition
一個返回 boolean 類型值的值表達式,它判斷哪些行需要被刪除。
OUTPUTS 輸出
成功時,DELETE 命令返回形如
DELETE count
的標簽。 count 是被刪除的行數(shù)。 如果 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;