Explain Alter Command. Give syntax of add and modify options.

Alter Command is use to make necessary changes in existing structure/schema of table. If  DBA/user wants to make changes in a table which was created earlier then one can use Alter command.

The alter command has following 4 options. 
Add
Modify
Drop
Rename

Add option:
The add option is use to add new column to existing table. To add new column/attribute one can use following syntax. 
SQL>Alter table table-name add attribute_name datatype(size); 
Example: 
SQL>Alter table student add hobby varchar2(10); 
Add Constraints:- 
Another use of add option is to add constraints on existing attribute. To add constraint following syntax is use. 
SQL>Alter table table-name add constraint constraint_name constraint_type(list of attribute(s)); 
SQL>Alter table student add constraint pk primary key(roll_no);

Modify option: 
The modify option is use to modify existing column of table. To modify column/attribute one can use following syntax. 
SQL>Alter table table-name modify attribute_name new_datatype(size); 
Example: 
SQL>Alter table student modify hobby varchar2(20); 


Post a Comment

0 Comments