PostgreSQL DROP TABLE语句用于删除表定义以及该表的所有关联数据,索引,规则,触发器和约束。
使用此命令时必须小心,因为一旦删除了表,那么表中所有可用的信息也将永远丢失。
语法
DROP TABLE语句的基本语法如下
DROP TABLE table_name;
举例
在上一章中,我们已经创建了表DEPARTMENT和COMPANY。首先,验证这些表(使用\d列出表)
testdb=> \d
这将产生以下结果
List of relations
Schema | Name | Type | Owner
--------+------------+-------+----------
public | company | table | postgres
public | department | table | postgres
(2 rows)
这意味着存在DEPARTMENT和COMPANY表。因此,让我们如下将它们删除
testdb=# drop table department, company;
这将产生以下结果
DROP TABLE
testdb=# \d
relations found.
testdb=#
返回的消息DROP TABLE表示drop命令已成功执行。