Postgresql 简明教程

PostgreSQL - DROP Table

PostgreSQL DROP TABLE 语句用于删除表定义以及该表的全部相关数据、索引、规则、触发器和约束。

The PostgreSQL DROP TABLE statement is used to remove a table definition and all associated data, indexes, rules, triggers, and constraints for that table.

Syntax

DROP TABLE 语句的基本语法如下 -

Basic syntax of DROP TABLE statement is as follows −

DROP TABLE table_name;

Example

我们在前一章中创建了 DEPARTMENT 和 COMPANY 表。首先,验证这些表(使用 \d 来列出这些表) -

We had created the tables DEPARTMENT and COMPANY in the previous chapter. First, verify these tables (use \d to list the tables) −

testdb-# \d

这将产生以下结果 -

This would produce the following result −

           List of relations
 Schema |    Name    | Type  |  Owner
--------+------------+-------+----------
 public | company    | table | postgres
 public | department | table | postgres
(2 rows)

这意味着 DEPARTMENT 和 COMPANY 表已存在。那么,让我们按如下方式将其丢弃 -

This means DEPARTMENT and COMPANY tables are present. So let us drop them as follows −

testdb=# drop table department, company;

这将产生以下结果 -

This would produce the following result −

DROP TABLE
testdb=# \d
relations found.
testdb=#

返回消息 DROP TABLE 指示已成功执行丢弃命令。

The message returned DROP TABLE indicates that drop command is executed successfully.