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.
- ON DELETE CASCADE option is optionally. this option will delete all the record when user delete any deptno from its parent table DEPT.
- dept is Parent table.
- all Child record will be deleted when its releted Parent table is deleted.
No comments:
Post a Comment