In SQL, Alter is a Data Definition Language (DDL) that is used to add, delete, or modify columns in an existing table. If an existing table has some constraints, Alter commands can also be used to change it.
In this post, we will add a new column in a SQL table using Alter command.
We will first create a table named ’employee’ using SQL query then we will further add a new column(s) in it using Alter command.
Creating a Table in SQL
create table employee(
id int,
name varchar(10)
address varchar(255)
);
Output:
id | name | address |
Adding a new column in the above table
alter table employee add country varchar(10);
Output:
id | name | address | country |
Adding multiple new columns in the table
alter table employee
add column phone VARCHAR(100),
add column PIN INT(10)
Output:
id | name | address | country | phone | PIN |