The SQL ALTER TABLE command is used to modify the definition (structure) of a table by modifying the definition of its columns. The ALTER command is used to perform the following functions.
1) Add, drop, modify table columns
2) Add and drop constraints
3) Enable and Disable constraints
For Example: To add a column "address" to the student table, the query would be like
For Example: To drop the column "age" from the student table, the query would be like
Syntax to modify a column
For Example: To modify the column fees in the student table, the query would be like
If you change the object's name any reference to the old name will be affected. You have to manually change the old name to the new name in every reference.
For Example: To change the name of the table
1) Add, drop, modify table columns
2) Add and drop constraints
3) Enable and Disable constraints
Syntax to add a column
ALTER TABLE table_name ADD column_name datatype;
For Example: To add a column "address" to the student table, the query would be like
ALTER TABLE employee ADD address varchar(500);
Syntax to drop a column
ALTER TABLE table_name DROP column_name;
For Example: To drop the column "age" from the student table, the query would be like
ALTER TABLE employee DROP age;
Syntax to modify a column
ALTER TABLE table_name MODIFY column_name datatype;
For Example: To modify the column fees in the student table, the query would be like
ALTER TABLE employee MODIFY fees number(15,2);
SQL RENAME Command
The SQL RENAME command is used to change the name of the table or a database object.If you change the object's name any reference to the old name will be affected. You have to manually change the old name to the new name in every reference.
Syntax to rename a table
RENAME old_table_name To new_table_name;
For Example: To change the name of the table
student to All_Students, the query would be like RENAME student TO All_Students;
Comments
Post a Comment