My Sql syntax and Examples.
1.) How to insert a column in table?
→ Syntax: Alter table <Table Name> add <Column Name Datatype(size)>;
→ Example: Alter table Student add Address varchar(20);
2.) How to insert multiple columns in table?
→ Syntax: Alter table <Table Name> add <Column Name Datatype(size), Column Name Datatype(size), Column Name Datatype(size)>;
→ Example: Alter table Student add (Col1 varchar(2), col2 number(5), col3 number(8));
3.) How to drop the specific column?
→ Syntax : Alter table <Table Name> drop column <Column Name>;
→ Example: Alter table Student drop column Address;
4.) How to drop the one or more column at a time?
→ Syntax : Alter table <Table Name> drop column <Column Name, Column Name>;
→ Example: Alter table Student drop column (col1, col2, col3, ......, col_n);
5.) How to rename the column?
→ Syntax : Alter table <Table Name> rename column <Old Column Name> to <New Column Name>;
→ Example: Alter table Student rename column Phone to Phone_Number;
6.) How to change or modify the datatype of single variable?
→ Syntax : Alter table <Table Name> modify <Column Name Datatype(Size)>;
→ Example: Alter table Student modify Name varchar(30);
7.) How to change or modify the datatype of multiple variables?
→ Syntax : Alter table <Table Name> modify <Column Name Datatype(Size), Column Name Datatype(Size)>;
→ Example: Alter table Student modify <Name varchar(30), Roll number(7)>;
0 Comments
Thank You ! For your love