方法1.在主表建立除法器。 方法2.在建立从表的时候指定,外键引用动作.create table tb1 (id int primary key) --insert into tb1(id) values(1) --insert into tb1(id) values(2) --insert into tb1(id) values(3) --select * from tb1 create table tb2 (id int primary key,rid int CONSTRAINT FK FOREIGN KEY REFERENCES tb1(id) ON DELETE CASCADE) --insert into tb2(id,rid)values(1,1) --insert into tb2(id,rid)values(2,2) --insert into tb2(id,rid)values(3,2) --insert into tb2(id,rid)values(4,3) --select * from tb2 --delete from tb1 where id = 2 --select * from tb2 --drop table tb1,tb2
方法2.在建立从表的时候指定,外键引用动作.create table tb1 (id int primary key)
--insert into tb1(id) values(1)
--insert into tb1(id) values(2)
--insert into tb1(id) values(3)
--select * from tb1
create table tb2 (id int primary key,rid int
CONSTRAINT FK FOREIGN KEY REFERENCES tb1(id) ON DELETE CASCADE)
--insert into tb2(id,rid)values(1,1)
--insert into tb2(id,rid)values(2,2)
--insert into tb2(id,rid)values(3,2)
--insert into tb2(id,rid)values(4,3)
--select * from tb2
--delete from tb1 where id = 2
--select * from tb2
--drop table tb1,tb2