SQL > ALTER TABLE > Drop Column Syntax

Sometimes we will wish to delete a column from an existing table in SQL. To do this, we specify that we want to change the table structure via the ALTER TABLE command, followed by a specification indicating that we want to remove a column. The detailed syntax for each database is as follow:

In MySQL, the syntax for ALTER TABLE Drop Column is,

ALTER TABLE "table_name"
DROP "column_name";

In Oracle and SQL Server, the syntax for ALTER TABLE Drop Column is,

ALTER TABLE "table_name"
DROP COLUMN "column_name";

Let's look at the example. Assuming our starting point is the Customer table created in the CREATE TABLE section:

Table Customer

Column NameData Type
First_Namechar(50)
Last_Namechar(50)
Addresschar(50)
Citychar(50)
Countrychar(25)
Birth_Datedatetime

Our goal is to drop the "Birth_Date" column. To do this, we key in:

MySQL:

ALTER TABLE Customer DROP Birth_Date;

SQL Server:

ALTER TABLE Customer DROP COLUMN Birth_Date;

Oracle:

ALTER TABLE Customer DROP COLUMN Birth_Date;

The resulting table structure is:

Table Customer

Column NameData Type
First_Namechar(50)
Last_Namechar(50)
Addresschar(50)
Citychar(50)
Countrychar(25)

Next: SQL ADD INDEX




Copyright © 2014 1keydata.com   All Rights Reserved.   Privacy Policy