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

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.