How do you ALTER TABLE in SQL ?
The SQL ALTER TABLE command is used to add, delete or modify columns in an existing table. You should also use the ALTER TABLE command to add and drop various constraints on an existing table
The ALTER TABLE statement is used to add, delete, or modify columns in an existing table. The ALTER TABLE statement is also used to add and drop various constraints on an existing table.
In many situations, you may require to add the columns in the existing table. Instead of creating a whole table or database again you can easily add single and multiple columns using the ADD keyword.
1 . ADD Column
Syntax of ALTER TABLE ADD Column statement in SQL
The above syntax only allows you to add a single column to the existing table. If you want to add more than one column to the table in a single SQL statement, then use the following syntax:
ADD Column in table output:
2 MODIFY Column
The MODIFY keyword is used for changing the column definition of the existing table.
Syntax of ALTER TABLE MODIFY Column
This syntax only allows you to modify a single column of the existing table. If you want to modify more than one column of the table in a single SQL statement, then use the following syntax:
MODIFY Column in table output:
3 DROP Column
In many situations, you may require to delete the columns from the existing table. Instead of deleting the whole table or database you can use DROP keyword for deleting the columns.
Syntax of ALTER TABLE DROP Column statement in SQL
DROP Column in table output:
4 RENAME Column
The RENAME keyword is used for changing the name of columns or fields of the existing table.
Syntax of ALTER TABLE RENAME Column
RENAME Column in table output:
SQL Tutorial
No comments:
Post a Comment