PostgreSQL - DROP Table
PostgreSQL DROP TABLE 语句用于删除表定义及其所有相关数据、索引、规则、触发器和约束。
使用此命令时必须小心,因为一旦表被删除,表中所有信息也将永久丢失。
Syntax
DROP TABLE 语句的基本语法如下 −
DROP TABLE table_name;
Example
我们在上一章中创建了 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 表示删除命令已成功执行。