Deletions

2.9. Deletions

Rows can be removed from a table using the DELETE command. Suppose you are no longer interested in the weather of Hayward. Then you can do the following to delete those rows from the table:

DELETE FROM weather WHERE city = 'Hayward';

All weather records belonging to Hayward are removed.

SELECT * FROM weather;

city | temp_lo | temp_hi | prcp | date

---------------+---------+---------+------+------------

San Francisco | 46 | 50 | 0.25 | 1994-11-27

San Francisco | 41 | 55 | 0 | 1994-11-29

(2 rows)

One should be wary of statements of the form

DELETE FROM tablename;

Without a qualification, DELETE will remove all rows from the given table, leaving it empty. The system will not request confirmation before doing this!

2.9 删除

使用delete命令删除表数据。假设你已经开始对Hayward的天气信息失去了兴趣,那么可以使用以下命令删除相关的数据:

DELETE FROM weather WHERE city = 'Hayward';

这样,Hayward相关的数据就都没有了。

SELECT * FROM weather;

city | temp_lo | temp_hi | prcp | date

---------------+---------+---------+------+------------

San Francisco | 46 | 50 | 0.25 | 1994-11-27

San Francisco | 41 | 55 | 0 | 1994-11-29

(2 rows)

一定要注意下面的这个语句:

DELETE FROM tablename;

表名后面没有任何限定条件的话,那么会将表中所有的数据清空。而且,在执行这条语句的时候,系统也不会再次让你确认的。所以,一定要注意!

你可能感兴趣的:(PostgreSQL,11.2,Documentation,Oracle,PostgreSQL,11.2,Documentation,Learning)