예, 방법이 있습니다. 외래 키 캐스케이드 삭제에 대해서는 mysql 문서를 확인하십시오.
예 :
CREATE TABLE parent (id INT NOT NULL,
PRIMARY KEY (id)
) ENGINE=INNODB;
CREATE TABLE child (id INT, parent_id INT,
INDEX par_ind (parent_id),
FOREIGN KEY (parent_id) REFERENCES parent(id)
ON DELETE CASCADE
) ENGINE=INNODB;
Insert into parent set id=1;
Insert into parent set id=2;
Insert into parent set id=3;
Insert into child set id=1, parent_id=1;
Insert into child set id=2, parent_id=1;
select * from parent;
select * from child;
delete from parent where id=1;
select * from parent;
select * from child;
ID
1
2
3
Record Count: 3; Execution Time: 0ms View Execution Plan
ID PARENT_ID
1 1
2 1
Record Count: 2; Execution Time: 0ms View Execution Plan
Record Count: 0; Execution Time: 1ms
ID
2
3
Record Count: 2; Execution Time: 0ms View Execution Plan
Record Count: 0; Execution Time: 0ms
나는 계단식 삭제 사용할 수 있습니다 어떻게 계단식 – sikas
와 함께 갈 것인가? 나는 나의 테이블에서 cd_id를 기본 테이블 키로 사용하고 있음을 알 수있다. 나는 그것을 삭제하면 모든 하위 항목도 삭제되어야한다고 생각합니까? –