How to Alter Table in Oracle Sql to Add Column and Modify Column
How to alter a table in SQL
Alter Table Command
A table in SQL can be altered by using alter table command. By using alter table command , we can add new columns to an existing table. We can also change specification of the existing columns of a table using Alter Table command.
Adding New Columns using Alter Table command.
To add new columns in an existing table, we can use add option.
The general syntax is given below:
Alter table tablename add( new column specification);
Suppose we want to add zipcode column in employee table.
SQL>Alter table employee add(zipcode number(10));
This will add a new column zipcode to employee table.
Modifying existing columns of a table
To modify specification of existing columns of a table ,we can use modify option with alter table command.
The general syntax for modifying existing columns is given below
Alter table tablename modify( column new_specification);
Suppose we wants to chamge filed width of ecode column from 4 to 6.
SQL>Alter Table employee modify( ecode char(6));
Note: Be careful while changing column specifications