ALTER Keyword
The Alter keyword is used when we want to modify something.
If we want to add a new column or delete any column, or if we want to change any procedure, or change any function, The alter command is used in all of the preceding scenarios.
The Alter command is used with another command like 'Alter Table', 'Alter Procedure', 'Alter Column', 'Alter Trigger', etc.
1) Alter Table
The ALTER TABLE command is used to add, delete, or modify columns in a table. It is also used to add, delete or modify the constraints.
Syntax
ALTER TABLE <TABLE_NAME> ADD <COLUMN_NAME> <DATATYPE>;
Example
ALTER TABLE Employee ADD Dept_Id Integer;
2) Alter Column
The ALTER Column command is used to change the data type of a column in a table.
Syntax
ALTER TABLE <TABLE_NAME> ALTER COLUMN <COLUMN_NAME> <DATATYPE>;
Example
ALTER TABLE Employee ALTER COLUMN Emp_DOB Date;
3) Alter Procedure
The ALTER Procedure command is used to modify a procedure.
Syntax
ALTER PROCEDURE <PROCEDURE_NAME>
AS
BEGIN
<STATEMENTS>
END
Example
ALTER PROCEDURE Get_Employee
AS
BEGIN
Select * From Employee;
END
4) Alter Trigger
The ALTER Trigger command is used to modify trigger.
Syntax
ALTER TRIGGER <TRIGGER_NAME>
ON <TABLE_NAME>
FOR <INSERT OR/AND UPDATE OR/AND DELETE>
AS
BEGIN
<STATEMENT>
END
Example
ALTER TRIGGER Track_Employee
ON Employee
FOR UPDATE
AS
BEGIN
Select * from Employee;
END
Summary
The Alter keyword is used when we want to modify something like Table, Procedure, Column, Trigger, etc.