SQL drop column

SQL drop column from table example-Learn how to remove column from a table in MySQL database with examples and important points.

To drop or remove column from a table, first we need to alter the table using SQL Alter command and then execute drop column query.

SQL drop column Syntax

ALTER TABLE [table_name]
Drop column [column_name];

SQL Drop Column Example

Consider the table BOOKS. Below query will remove column name ‘PRICE’ from Books Table.

ALTER TABLE BOOKS
ADD PRICE FLOAT;

NOTE:

If the constrain like NOT NULL Constraint, DEFAULT Constraint, CHECK Constraint or PRIMARY KEY Constraint are there on the column, then above query will also work.

If there is a FOREIGN KEY constrain on parent table then first we need to remove columns from child table. Then, we can remove the column from master table using the same mentioned query.

Related Posts