SQL ADD COLUMN
In this SQL article, you will learn about the ADD COLUMN command in detail with syntax and examples.
What is ADD COLUMN Statement?
In many SQL situations, you may require to add the new columns or fields in the existing table. So, SQL provides the ADD keyword with ALTER TABLE command to overcome this situation.
The ALTER TABLE and CREATE TABLE are the two different statements in Structured Query Language that allows you to add columns. But the difference between the both statements is that CREATE statement adds columns at the time of table creation, whereas ALTER statement adds one or more columns later in the existing table.
Syntax of ADD Column statement
This ALTER TABLE syntax allows us to add a single new field to the existing table.
If you want to add more than one new field to the table in a single SQL query, you have to use the following syntax:
Examples of ADD Column statement in SQL
Here, we took the following two different examples of Structured Query Language, which will help us to add single and multiple fields in the existing table:
Firstly, we create the Teacher_Details table and then insert the dummy records into the Teacher_Details table.
The following INSERT query inserts the record of teachers into the above table:
The following query displays the record of the Teacher_Details table:
The following query adds the new Teacher_MailID column into the above Teacher_Details table:
Let's take another example which adds multiple columns into the table. Let's start by creating another Customer table:
The following query inserts the multiple records into the Customer table:
The following query adds two new columns in the Customer table:
Next TopicHow to use Auto-Increment in SQL