Delete or Modify Table ALTER TABLE statement will allow you to add
new column or constraint, modify existing column or constraint, and drop
existing column or existing constraint after the table is created. The following statement will add a
middle name column to the employees table.
ALTER TABLE employees ADD middle_name VARCHAR2(25);
|
The statement bellow modifies the last_name to required column. This
statement works when there no null last name exist now.
ALTER TABLE employees MODIFY last_name NOT NULL;
|
This statement deletes the above column.
ALTER TABLE employees DROP last_name;
|
Adding, and deleting constraints are similar to those of the
column. Here is an statement to add a foreign key to employees table.
ALTER TABLE employees ADD
FOREIGN KEY (department_id) NUMBER REFERENCES department;
| To delete a column or constraint use DROP followed
by the column or constraint name in the position of ADD or
MODIFY.
Constraints can be turned off temporarily instead of dropping it, by using
DISABLE/ENABLE clause
within the alter table statement. The bellow statement turns off the
primary key for employees table. ENABLE
is used when turning it on. ALTER TABLE employees DISABLE PRIMARY KEY;
|