Alter Table command in SQL? Add & drop column from existing table using SQL.

Aman Sharma
0

ALTER TABLE Statement in SQL:
To add, delete, or modify columns in an existing table, we use ALTER TABLE statement.  We can also use it to add and drop various constraints on an existing table.

1.       Add Column to existing Table: we use following syntax to add column.


Syntax :

ALTER TABLE tableName
ADD columnName datatype;

Example:  Add Age column to tblStudent table:

ALTER TABLE tblStudent
ADD Age int;




2.  Delete or Drop Column from Existing table: 

Syntax to Delete column:

ALTER TABLE TableName
DROP COLUMN ColumnName;

Example: Query to delete column Age from tblStudent table in SQL:

ALTER TABLE tblStudent
DROP COLUMN Age;


3.  ALTER TABLE - ALTER COLUMN:
We can also change datatype of existing column using Alter table statement:

Syntax:

ALTER TABLE TableName
ALTER COLUMN ColumnName datatype;

Example: Query to change datatype of column Age of tblStudent table :

ALTER TABLE tblStudent
ALTER COLUMN Age varchar(50);









Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !