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命令已成功执行.