DBMS | ALTER TABLE Command | Exp - 2
ALTER TABLE Command
ALTER TABLE is used to add, delete/drop or modify columns in the existing table. It is also used to add and drop various constraints on the existing table.
The ALTER command is used to perform the following functions.
1. ADD
ADD is used to add columns into the existing table. Sometimes we may require to add additional information, in that case we do not require to create the whole database again, ADD comes to our rescue.
Syntax:
ALTER TABLE table_name
ADD column_name datatype;
2. DROP
DROP COLUMN is used to drop column in a table. Deleting the unwanted columns from the table.
Syntax:
ALTER TABLE table_name
DROP COLUMN column_name;
3. MODIFY/ ALTER
MODIFY is used to modify the existing columns in a table. Multiple columns can also be modified at once.
Syntax(Oracle,MySQL,MariaDB):
ALTER TABLE table_name
MODIFY column_name column_type;
Syntax(SQL Server):
ALTER TABLE table_name
ALTER COLUMN column_name column_type;
Problem Statement
Company want to add & remove some attribute and also want to modify the properties of existing attribute such as data type, size and constraints.
File: Download here
No comments: