SQL DROP COLUMN Statement

The DROP COLUMN statement in SQL is used to remove a column from an existing table. This is a destructive operation; the column and all its data will be permanently deleted.



DROP COLUMN: Definition and Usage

DROP COLUMN is used to modify the structure of a table by removing a column. This is typically done when a column is no longer needed or if the table's design needs to be changed. Use this command carefully, as the data within the column is permanently lost unless you have a database backup.

Syntax

Syntax

ALTER TABLE table_name
DROP COLUMN column_name;
      

Example

Deleting a Column

This example demonstrates removing the "ContactName" column from the "Customers" table. (This assumes a table named 'Customers' already exists with a column named 'ContactName'.)

Syntax

ALTER TABLE Customers
DROP COLUMN ContactName;
      
Output

(The ContactName column and its data are permanently removed from the Customers table.)
      

**Important Note:** Always back up your database before dropping a column, as this action cannot be easily undone without a backup. The data in the dropped column is lost permanently.