SQL > SQL ALTER TABLE > Add Column Syntax

To add a column to a table using SQL, we specify that we want to change the table structure via the ALTER TABLE command, followed by the ADD command to tell the RDBMS that we want to add a column.

The ALTER TABLE ADD COLUMN statement lets you insert a new column into an existing table without losing any data. The new column is appended to the end of the table and the syntax varies slightly across database platforms.

Syntax

For MySQL, Oracle, and SQL Server, the syntax for ALTER TABLE Add Column is,

ALTER TABLE "table_name"
ADD "column_name" "Data Type";

For Google BigQuery, the syntax for ALTER TABLE Add Column is,

ALTER TABLE "table_name"
ADD COLUMN "column_name" "Data Type" [, ...];

For SparkSQL and Hive SQL (HiveQL), the syntax for ALTER TABLE Add Column is,

ALTER TABLE "table_name"
ADD COLUMNS "column_name" "Data Type";

Examples

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 

Example 1: Add one column to a table

Our goal is to add a column called "Gender". To do this, we key in:

MySQL:

ALTER TABLE Customer ADD Gender char(1);

Oracle:

ALTER TABLE Customer ADD Gender char(1);

SQL Server:

ALTER TABLE Customer ADD Gender char(1);

Google BigQuery:

ALTER TABLE Customer ADD COLUMN Gender char(1);

SparkSQL:

ALTER TABLE Customer ADD COLUMNS Gender char(1);

HiveQL:

ALTER TABLE Customer ADD COLUMNS Gender char(1);

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) 
 Birth_Date  datetime 
 Gender  char(1) 

Note that the new column Gender becomes the last column in the Customer table.

Example 2: Add multiple columns to a table

It is also possible to add multiple columns. To do so, start with a parenthesis, then add each column name and its data type separated by comma, in the order that you want the columns to appear.

For example, if we want to add a column called "Email" and another column called "Telephone", we will type the following:

MySQL:

ALTER TABLE Customer ADD (Email char(30), Telephone char(20) );

Oracle:

ALTER TABLE Customer ADD (Email char(30), Telephone char(20) );

SQL Server:

ALTER TABLE Customer ADD (Email char(30), Telephone char(20) );

Google BigQuery:

ALTER TABLE Customer ADD COLUMN Email char(30), ADD COLUMN Telephone char(20);

SparkSQL:

ALTER TABLE Customer ADD COLUMNS (Email char(30), Telephone char(20) );

HiveQL:

ALTER TABLE Customer ADD COLUMNS (Email char(30), Telephone char(20) );

The table now becomes:

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 
 Gender  char(1) 
 Email  char(30) 
 Telephone  char(20) 

Please note that Spark only has a string data type. Specifying a data type of char() will work in SparkSQL, but the new column will have a data type of string.

Frequently Asked Questions

Q: Does adding a column affect existing data in the table?
A: No. Existing rows are not affected — the new column is added with a NULL value (or the column's DEFAULT value) for all existing rows.
Q: Can I specify a default value when adding a column?
A: Yes. You can add a DEFAULT clause to the column definition, e.g., ALTER TABLE Customer ADD Status char(10) DEFAULT 'Active';
Q: What is the difference between ADD and ADD COLUMN?
A: In MySQL and Oracle, you can use either ADD or ADD COLUMN interchangeably for a single column. BigQuery requires ADD COLUMN explicitly, while SparkSQL/HiveQL require ADD COLUMNS (plural).
Q: Can I add a NOT NULL column to a table that already has rows?
A: Only if you also supply a DEFAULT value. Without a default, adding a NOT NULL column to a non-empty table will fail because existing rows would have no value for the new column.

Next: SQL CHANGE COLUMN

This page was last updated on March 19, 2026.




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