English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Delete a Table in PostgreSQL

PostgreSQL uses the DROP TABLE statement to delete tables, which includes table data, rules, triggers, etc., so you should be cautious when deleting tables, as all information will be deleted after deletion.

Syntax

DROP TABLE The syntax format is as follows:

DROP TABLE table_name;

Online Examples

In the previous chapter, we created the tables COMPANY and DEPARTMENT. We can first use the \d command to check if the tables have been created successfully:

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

From the above results, we can see that our tables have been created successfully, and next we will delete these two tables:

w3codeboxdb=# drop table department, company;
DROP TABLE

Use the \d command again to check and you won't find the table:

testdb=# \d
Did not find any relations.