Easy Tutorial
❮ Postgresql Create Database Postgresql Operators ❯

PostgreSQL Deleting Tables

PostgreSQL uses the DROP TABLE statement to delete tables, which includes the table data, rules, triggers, etc. Therefore, deleting a table should be done with caution, as all information will be lost once the table is deleted.

Syntax

The DROP TABLE syntax is as follows:

DROP TABLE table_name;

Example

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

tutorialprodb=# \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 the tables were created successfully. Next, we will delete these two tables:

tutorialprodb=# drop table department, company;
DROP TABLE

Using the \d command again will show that the tables are no longer present:

testdb=# \d
Did not find any relations.
❮ Postgresql Create Database Postgresql Operators ❯