Oracle

Adding a Constraint Syntax

Figo Kim 2007. 1. 9. 23:04
ALTER TABLE  <table_name>
ADD [CONSTRAINT  <constraint_name.]
type (<column_name>);
  • Enable or Disable a constraint
  • Can't modify
  • Add "NOT NULL" by using "MODIFY" clause

    Only if the table is empty or every row of the table is filled.
ALTER TABLE emp2
modify employee_id Primary Key;

ALTER TABLE emp2
ADD CONSTRAINT emp_mgr_fk
FOREIGN KEY(manager_id) REFERENCES emp2(employee_id)


ALTER TABLE emp2 ADD CONSTRAINT emp_dt_fk
FOREIGN KEY (Department_id)
REFERENCES departments ON DELETE CASCADE;
** When data in the parent key is deleted, all rows in the child table that depend on the delete parent key values are also deleted.