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, SQL Server, and Google BigQuery, 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 Name  Data Type 
 First_Name  char(50) 
 Last_Name  char(50) 
 Address  char(50) 
 City  char(50) 
 Country  char(25) 
 Birth_Date  datetime 

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;

Google BigQuery:

ALTER TABLE Customer DROP COLUMN Birth_Date;

The resulting table structure is:

Table Customer

 Column Name  Data Type 
 First_Name  char(50) 
 Last_Name  char(50) 
 Address  char(50) 
 City  char(50) 
 Country  char(25) 

Next: SQL ADD INDEX

This page was last updated on October 19, 2023.




Copyright © 2024   1keydata.com   All Rights Reserved     Privacy Policy     About   Contact