PostgreSQL Drop Table
PostgreSQL uses the DROP TABLE statement to delete tables, including table data, rules, triggers, etc. Therefore, be careful when deleting tables, as all information disappears after deletion.
Syntax
DROP TABLEThe syntax format is as follows:
DROP TABLE table_name;
Examples
In the previous chapter, we created two tables, COMPANY and DEPARTMENT. We can first use\dcommand to check whether the tables were created successfully:
exampledb=# \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. Next, we delete these two tables:
exampledb=# drop table department, company; DROP TABLE
Then use\dcommand to check again, and the tables can no longer be found:
testdb=# \d Did not find any relations.Other Extensions