The ALTER TABLE statement is used to add, delete or modify a table column. It can also be used to rename a table and to add or drop constraints on a table.
Syntax of ALTER TABLE to add a new column:
ALTER TABLE tableName ADD columnName datatype;
Example:
Syntax of ALTER TABLE to add multiple columns:
Example:
Output:
Syntax of ALTER TABLE to modify a column:
ALTER TABLE tableName MODIFY columnNme datatype;
Example:
Output:
Syntax of ALTER TABLE to drop a column:
ALTER TABLE tableName DROP COLUMN columnName;
Example:
Output:
Syntax of ALTER TABLE to rename a column:
ALTER TABLE tableName RENAME COLUMN oldColumnName to newColumnName;
Example:
Output:
Syntax of ALTER TABLE to DROP CONSTRAINT from a table:
ALTER TABLE tableName DROP CONSTRAINT constraintName;
No comments:
Post a Comment