Oracle/SQL Fundamentals I
11일차 # 9-27: FOREIGN KEY constraints
Bohemian life
2012. 4. 18. 20:39
* ON DELETE CASCADE
delete from d1
where deptno = 30;
==> 오류: ORA-02292: 무결성 제약조건(MVP20.E1_DEPTNO_FK)이 위배되었습니다- 자식 레코드가 발견되었습니다
alter table e1
drop constraint e1_deptno_fk;
alter table e1
modify (deptno constraint e1_deptno_fk references d1(deptno)
on delete cascade);
delete from d1
where deptno = 30;
select * from d1;
select * from d2;
* ON DELETE SET NULL
delete from d2
where deptno = 30;
==> 오류: ORA-02292: 무결성 제약조건(MVP20.E2_DEPTNO_FK)이 위배되었습니다- 자식 레코드가 발견되었습니다
alter table e2
drop constraint e2_deptno_fk;
alter table e2
modify (deptno constraint e2_deptno_fk references d2(deptno)
on delete set null);
delete from d2
where deptno = 30;
select * from d2;
select * from e2;