PostgreSQL DROP Keyword
The PostgreSQL DROP keyword is used to delete a COLUMN, CONSTRAINT, DATABASE, INDEX, TABLE, or VIEW.
DROP COLUMN
To drop the Age column from table called Employee, the following statement can be used:
ALTER TABLE Employee DROP COLUMN Age;
DROP a UNIQUE Constraint
To drop UC_Employee UNIQUE constraint from table called Employee, the below mentioned statement can be used:
ALTER TABLE Employee DROP CONSTRAINT UC_Employee;
DROP a PRIMARY KEY Constraint
To drop PK_Employee PRIMARY KEY constraint from table called Employee, the statement is given below:
ALTER TABLE Employee DROP CONSTRAINT PK_Employee;
DROP a FOREIGN KEY Constraint
To drop FK_Contact_Info FOREIGN KEY constraint from table called Contact_Info, the statement is given below:
ALTER TABLE Contact_Info DROP FOREIGN KEY FK_Contact_Info;
DROP a CHECK Constraint
To drop CHK_Employee CHECK constraint from table called Employee, the statement is given below:
ALTER TABLE Employee DROP CONSTRAINT CHK_Employee;
DROP DEFAULT constraint
To drop DEFAULT constraint from City column of Employee table, the following statement can be used:
ALTER TABLE Employee ALTER City DROP DEFAULT; OR ALTER TABLE Employee ALTER COLUMN City DROP DEFAULT;
DROP INDEX
Consider a database which contains an index named idx_name. To drop this index, the following statement can be used:
DROP INDEX idx_name;
DROP DATABASE
To drop an existing database with name testDB, the following statement can be used:
DROP DATABASE testDB;
DROP TABLE
To drop a table name Employee, the following statement can be used:
DROP TABLE Employee;
DROP VIEW
To drop EmployeeInIndia view from table called Employee, the below statement can be used:
DROP VIEW EmployeeInIndia;
❮ PostgreSQL Keywords