Azure SQL Alter Table Statement

In this article we will learn about the Azure SQL alter statement. In the previous article we have learned how create and connect to the Azure SQL database. If you are new to the Azure SQL, then please watch my following videos on the Azure SQL database.

How To Create Azure SQL DataBase

How To Connect Azure SQL DataBase Using SQL Management Studio


What is SQL Alter Table Statement?

Alter statement used to modify the structure of the existing table. The alter statement used is to add, drop the table column. It can also be used to change the data types of the column etc.
Let us consider we have the table having name Employee in our Azure SQL Server database having the following records,



Add Column To Existing Table Using Alter Statement

The following SQL query will add the new column Salary into the existing table.

ALTER TABLE Employee
ADD salary  decimal(50);

You can alter the multiple columns at a time, the following query will alter the multiple columns of the existing table.

ALTER TABLE Employee ADD
(
Location varchar (50),
EmailID Varchar (50)
)

Modify The Existing Table Column
You can rename or change the data type of the column using the alter statement.
Example
ALTER TABLE Employee 
MODIFY Salary  decimal(60);

The preceding query will change the Salary column data type size to 60 from previous 50.
Drop The Column of Existing Table

ALTER TABLE Employee
DROP COLUMN Salary;

The preceding SQL query will remove the Salary column from the existing Employee table.
Summary
I hope from all the above demonstration, you have learned about the Azure SQL Alter statement and its uses of the Alter statement.

Related Article

Post a Comment

www.CodeNirvana.in

Protected by Copyscape
Copyright © Compilemode