Thursday, April 25, 2013

Add new Column with Foreign key Constraint


ADDING NEW COLUMN AFTER TABLE CREATION  with FK Constraint

 alter table emp
 add deptno number(3,0)
 add constraint fk_deptno
 foreign key (deptno) references dept(deptno)
on delete cascade

after above option  table  EMP will be  look like


  • Here DEPTNO is Foreign key of DEPT table.


  1. ON DELETE CASCADE option is  optionally.  this  option will  delete all the record when user delete any deptno from its parent table DEPT.
  2. dept is Parent table.
  3. all Child record  will be deleted when its releted Parent table is deleted.

No comments:

Post a Comment