개인 공부/Oracle
참고하고있는 것 무시하고 삭제, 참고하고 있는 것들도 자동 삭제
이대곤
2022. 9. 21. 15:15
누군가 나의 테이블을 참고하고 있더라도 무시하고 테이블을 삭제하고자 할 때
drop table 테이블명 cascade constraints;
참조하고 있는 레코드가 삭제되면 나 자신의 레코드도 자동으로 삭제되도록 할 때
references 참조하는테이블(참조하는 열이름) on delete cascade
통합예시
-- to ignore being refered by other table
drop table prod cascade constraints;
create table prod(
no number primary key,
id varchar2(10)
);
-- to ignore being refered by other table
drop table wishlist cascade constraints;
create table wishlist(
no number primary key,
pno number references prod(no) on delete cascade
);
insert into prod values(1, 'apple');
insert into wishlist values(1, 1);
-- with this, also wishlist record is deleted automatically
delete from prod where no = 1;