T-SQL Tutorial

SQL DROP COLUMN


In this article we will show the syntax and example how to DROP COLUMN from a table. In SQL Server, the ALTER TABLE statement is used to drop a column from a table.

DROP COLUMN syntax

The basic syntax is as follows:

ALTER TABLE table_name
DROP COLUMN column_name


DROP COLUMN examples


For example, to drop a column named "address" from a table named "customers", the following SQL statement would be used:

ALTER TABLE customers
DROP COLUMN address;


It's important to note that when you drop a column, all data stored in that column will be permanently deleted and cannot be recovered. Additionally, any indexes or constraints that reference the dropped column will also be removed.

Also, it is important to backup the data before making any modification on the table because it is a DDL statement and it may cause data loss. It is also important to note that column can only be dropped if it does not have any reference key and it is not being used in any constraint.


Employee table

Column nameData_type
idint
namevarchar(250)
dep_idint
addressvarchar(400)

Example

ALTER TABLE employee
DROP COLUMN address;


Result

Column nameData_type
idint
namevarchar(250)
dep_idint