Sunday, 19 May 2019

Postgres: Drop table

'DROP TABLE' command is used to drop a table.

 

Syntax

DROP TABLE table_name;


Step 1: Create a database myOrg.
createdb -U postgres -h localhost myOrg

Step 2: Login to myOrg database and execute the command \d to list all the tables in this database.
$psql -U postgres -h localhost --dbname=myOrg
Password for user postgres: 
psql (14.4)
Type "help" for help.

myOrg=# 
myOrg=# \d
Did not find any relations.
   \d command print all table in a database.

Create table employee.

CREATE TABLE employee (id INT, name VARCHAR(20));

myOrg=# CREATE TABLE employee (id INT, name VARCHAR(20));
CREATE TABLE
myOrg=# 
myOrg=# \d
          List of relations
 Schema |   Name   | Type  |  Owner   
--------+----------+-------+----------
 public | employee | table | postgres
(1 row)

Step 3: Drop employee table.

myOrg=# DROP TABLE employee;
DROP TABLE
myOrg=# 
myOrg=# \d
Did not find any relations.
myOrg=# 



Previous                                                 Next                                                 Home

No comments:

Post a Comment