English 中文(简体)
PostgreSQL Tutorial

Advanced PostgreSQL

PostgreSQL Interfaces

PostgreSQL Useful Resources

Selected Reading

PostgreSQL - Drop Table
  • 时间:2024-12-27

PostgreSQL - DROP Table


Previous Page Next Page  

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 pst the tables) −

testdb-# d

This would produce the following result −

           List of relations
 Schema |    Name    | Type  |  Owner
--------+------------+-------+----------
 pubpc | company    | table | postgres
 pubpc | 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