PostgreSQL 刪除表格

PostgreSQL 刪除表格

PostgreSQL 使用 DROP TABLE 語句來刪除表格,包含表格資料、規則、觸發器等,所以刪除表格要慎重,刪除後所有資訊就消失了。

語法

DROP TABLE 語法格式如下:

DROP TABLE table_name;

例項

上一章節中我們建立了 COMPANY 和 DEPARTMENT 兩個表格,我們可以先使用 \d 命令來查看錶格是否建立成功:

itread01db=# \d
           List of relations
 Schema |    Name    | Type  |  Owner   
--------+------------+-------+----------
 public | company    | table | postgres
 public | department | table | postgres
(2 rows)

從以上結果可以看出,我們表格已經建立成功,接下來我們刪除這兩個表格:

itread01db=# drop table department, company;
DROP TABLE

再使用 \d 命令來檢視就找不到表格了:

testdb=# \d
Did not find any relations.