TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

PostgreSQL Drop Table

PostgreSQL Drop Table for beginners and professionals with examples database, table, create, select, insert, update, delete, join, function, index, clause, trigger, view, procedure etc.

<< Back to POSTGRESQL

PostgreSQL Drop/Delete Table

In PostgreSQL, we can use the Drop table command to delete the existing table or which we don't need anymore. This command deletes the complete data of a table along with the whole structure or definition permanently from the database.

So, we must be very alert while deleting the table because we cannot recover the lost data after removing it.

In this section, we are going to learn how to drop and delete a table in PostgreSQL.

The syntax for Dropping a table

DROP TABLE table_name;

Here the table name parameter is used to define the name of the table, which we will delete from the database. And the drop table is the keyword which is used to drop a table.

In PostgreSQL, we can drop the table in two ways:

  • Dropping a table from psql
  • Drop table in pgAdmin

Dropping a table from psql

To drop/delete or remove in psql, we are going to follow the below steps:

Step1

We had created the table Student and Department in the previous section of the tutorial. First, we will confirm these tables with the help of below command:

TheDeveloperBlog=# \d

After using the above command, the following output will occur:

PostgreSQL Drop/Delete Table

Step2

This means that the Student and Department tables are available in the selected database. Thus, we will let drop them with the help of below command:

TheDeveloperBlog=# drop table student, department;

PostgreSQL Drop/Delete Table

Step3

And if we again check for the list of relations:

TheDeveloperBlog=# \d
relations found.
TheDeveloperBlog=# 

The above message specifies that drop command is executed successfully.

Drop table in pgAdmin

And if we want to drop a table from the pgAdmin, we need to follow the below process:

Step1

Open your pgAdmin and then go the object tree where we will go to the database and then move to the public section under schemas and then select the Employee table which we want to delete or drop.

PostgreSQL Drop/Delete Table

Step2

Then we will right-click on the selected (Employee) table, and click on the Delete/Drop option from the given drop-down list as we can see in the below screenshot:

PostgreSQL Drop/Delete Table

Step3

The drop table popup window will appear on the screen, where we will click on the Yes button to drop the Employee table.

PostgreSQL Drop/Delete Table

Step4

Once we clicked on the Yes button, the table will be deleted automatically, as we can see in the below screenshot that there is no table available in the Table section.

PostgreSQL Drop/Delete Table




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf