3. Alter table
“The ALTER TABLE statement is used
to add, delete, or modify columns in
an existing table.”
Alter Table command perform Five types task
1. Add New Column
2. Delete Old Column
3. Modify Column Width
4. Change the column Name
5. Rename the table Name
5. Add New Column
This method ,To add a New column in a Old table
Syntax Example
ALTER TABLE table_name
ADD column_name datatype;
ALTER TABLE Student
ADD city varchar(20);
6.
7. Delete Old Column
This method , Delete a old column in a table
Permanently
Syntax Example
ALTER TABLE table_name
Drop Column COLUMN_NAME ;
ALTER TABLE Student
Drop Column city ;
8.
9. Modify Column Width
In This Method, To change the column width of a
column in a table
Syntax Example
ALTER TABLE table_name
Modify column_name datatype;
ALTER TABLE Student
Modify Student_Name varchar(20);
10.
11. Change the column Name
This method , Used to change the old column
Name to New column name in a table
Syntax
ALTER TABLE table_name
CHANGE Old column_name
New_Column_Name datatype;
Example
ALTER TABLE STUDENT
CHANGE T_Marks Tmarks int(3);
12.
13. Rename the table Name
This method used to ALTER TABLE to
rename the name of table.
Syntax Example
ALTER TABLE table_name
RENAME TO new_table_name;
ALTER TABLE Student
RENAME TO S_Record;