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),

alter table in sql example

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.

alter table in sql example

2) To add multiple columns in the table

ALTER TABLE Student ADD (Gender varchar(1), Percentage varchar(11));

This will add multiple columns/fields.

adding multiple cols using alter table in sql example

3) To drop a column in the table

ALTER TABLE Student DROP COLUMN Gender;

This drop the column gender.

dropping a col using alter table in sql example

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.




Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.