Home »
SQL
SQL - ALTER TABLE statement (to modify table definition)
SQL - ALTER TABLE statement: Here, we will learn how to modify a table’s definition like adding columns, removing columns, changing the data type size etc.
Submitted by Shubham Singh Rajawat, on November 14, 2017
ALTER TABLE statement is used to modify the definition/structure of the table. We can use ALTER TABLE to add, drop and modify fields/constraints of the table.
Sample table (Student),
1) To add a column in the table
ALTER TABLE Student ADD Gender varchar(1);
This will add a new field of the name gender in the table.
2) To add multiple columns in the table
ALTER TABLE Student ADD (Gender varchar(1), Percentage varchar(11));
This will add multiple columns/fields.
3) To drop a column in the table
ALTER TABLE Student DROP COLUMN Gender;
This drop the column gender.
4) To modify a column in the table
ALTER TABLE Student MODIFY COLUMN Physics integer;
This will convert the data type of Physics column of Student table.