MariaDB Tutorial MariaDB Advanced MariaDB Database Account Management MariaDB References

MariaDB DROP Keyword



The MariaDB 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 query 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 query can be used:

ALTER TABLE Employee
DROP INDEX UC_Employee;

DROP a PRIMARY KEY Constraint

To drop PK_Employee PRIMARY KEY constraint from table called Employee, the query is given below:

ALTER TABLE Employee
DROP PK_Employee;

OR 

ALTER TABLE Employee
DROP PRIMARY KEY;

DROP a FOREIGN KEY Constraint

To drop FK_Contact_Info FOREIGN KEY constraint from table called Contact_Info, the query 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 query is given below:

ALTER TABLE Employee
DROP CHECK CHK_Employee;

DROP DEFAULT constraint

To drop DEFAULT constraint from City column of Employee table, the query is given below:

ALTER TABLE Employee
ALTER City DROP DEFAULT;

DROP INDEX

Consider a table called Employee which contains an index named idx_name. To drop this index following query can be used:

ALTER TABLE Employee
DROP INDEX idx_name;

DROP DATABASE

To drop an existing database with name testDB, the following query can be used:

DROP DATABASE testDB;

Note: Extra measures should be taken while dropping a database. Deleting a database will result in loss of complete information stored in the database.

DROP TABLE

To drop a table name Employee, the following query can be used:

DROP TABLE Employee;

Note: Be careful before dropping a table. Once deleted, all information stored in that table will be lost forever!.

DROP VIEW

To drop EmployeeInIndia view from table called Employee, the below query can be used:

DROP VIEW EmployeeInIndia;

❮ MariaDB Keywords

5