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.

You have to be careful while using this command because once a table is deleted then all the information available in the table would also be lost forever.

Syntax

Basic syntax of DROP TABLE statement is as follows −

DROP TABLE table_name;

Example

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)

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=# 

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

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *