PostgreSQL - How to Drop a Table?

PostgreSQL: How to Drop a Table in PSQL and DbSchema

Table of Contents

  1. Introduction to PostgreSQL
  2. How to Delete a Table in PSQL
  3. How to Delete a Table in DbSchema
  4. Precautions When Deleting Tables
  5. Conclusion
  6. References


Install PostgreSQL alt >

PostgreSQL, commonly known as “Postgres,” is a free and open-source relational database management system (RDBMS) emphasizing extensibility and SQL compliance. It is equipped with a powerful set of features such as full ACID compliance, robustness, and performance, which enable you to manage your data no matter how big or small the dataset. In addition, it has a strong reputation for data integrity and correctness.In this article, we will explore two methods for deleting tables from a database: using the psql command-line interface and using DbSchema, a visual database design tool.

How to Delete a Table in PSQL

  1. Step 1: Firstly, we will connect to our database.To do so you can get read our article on the topic “PostgreSQL-How to Create Database?”.

  2. Step 2: After successfully establishing the connection with the database , we will check all the available databases. To do so we will use following command:

postgres=# \l
List of Databases
Name      | Owner
postgres  | postgres
template0 | postgres 
test      | postgres
  1. Step 3: Next, we will access/select the database where the table to be deleted is located. To do so, type “\c” followed by database name.Suppose our database name is example.
postgres=# \c example
Now you are connected to database example as user postgres

Here,”\c” represents a command while “example” is the database to be accessed.

  1. Step 4: Once you get connected to the database and select the database where the table to be deleted is to be located. The next step is to check all the available tables within the targeted database. To do so we run “\d” command.
List of Relations
Schema      | Name
public  | countries
public  | citites
  1. Step 5: Once we get the list of all the available tables in the targeted databases, we can now drop the tables which we want to delete.

In PostgreSQL, the DROP TABLE statement is used to delete an existing table.

Here’s a simple example:

DROP TABLE IF EXISTS company_details , team_details ;

In this example, the DROP TABLE command is used to delete the tables named “company_details”. The IF EXISTS clause is optional and prevents an error from occurring if the “Employees” table does not exist. It’s a good practice to use this clause to avoid potential issues in your SQL script.


Remember, DROP TABLE completely removes the table structure and associated data, constraints, triggers, etc. So be very sure that you indeed want to completely remove the table before executing the command.

Precautions When Deleting Tables

Deleting a table is a destructive operation and cannot be undone. Here are some precautions to consider:

  • Backup your data: Always make sure to have a backup of your data before deleting a table.
  • Check dependencies: Before deleting a table, check if other objects in the database (like views, stored procedures, triggers) depend on it.
  • Use transactions: Use the BEGIN, COMMIT, and ROLLBACK commands to control transactions, so if something goes wrong, you can rollback the operation.

Drop Tables and Visually Manage PostgreSQL using DbSchema

DbSchema is a PostgreSQL client and visual designer. DbSchema has a free Community Edition, which can be downloaded here.

Drop Table >

Drop Table

Start the application and connect to the Postgres database. Right-click any table header from the layout and choose Drop table.

DbSchema Designer alt >

Interactive Diagrams

Design tables, column and foreign keys directly in diagrams.

Connection Dialog alt >

Simple Connection Dialog

Choose the database location, the user and password, and simply get connected.

Relational Data Explorer alt >

Relational Data Explorer

Explore data from multiple tables simultaneously, using foreign keys or virtual foreign keys.

Query Builder alt >

Query Builder

Create SQL Queries using the mouse.

SQL Query Editor alt >

SQL Query Editor

Edit and execute SQL Queries

Schema Synchronization alt >

Design Schema in Team & Schema Deployment

DbSchema is using the design model, a copy of the schema structure, independent of the database.
The design model can be saved to file and shared in a team.
Connecting to another database you may compare the design model with the database, commit the differences or merge them in the design model.

Dark Theme alt >

Dark Theme

Configurable styles & dark theme.


Deleting tables in PostgreSQL, whether using PSQL or DbSchema, is a straightforward process. However it is crucial to exercise caution when deleting tables, as it is an irreversible action that permanently removes the table and its associated data. Always double-check dependencies and ensure you have a backup of your data before proceeding.

PostgreSQL provides the DROP TABLE statement in PSQL, allowing you to delete tables with ease. DbSchema, on the other hand, offers a visual interface that simplifies the process of deleting tables within the Schema Designer.

By following the steps outlined in this article, you can confidently delete tables in either PSQL or DbSchema, depending on your preference and requirements.


  1. PostgreSQL Official Documentation:
  2. DbSchema Documentation:
  3. SQL Syntax:
  4. PostgreSQL Tutorial:
  5. DbSchema Interactive Diagrams:

Please refer to the official documentation for PostgreSQL and DbSchema for the most up-to-date information and additional details on deleting tables.