on delete cascade当你更新或删除主键表时,那么外键表也会跟随一起更新或删除,需要在建表时设置级联属性
CREATE TABLE Countries(CountryId INT PRIMARY KEY)
INSERT INTO Countries (CountryId) VALUES (1)
INSERT INTO Countries (CountryId) VALUES (2)
INSERT INTO Countries (CountryId) VALUES (3)CREATE TABLE Cities( CityId INT PRIMARY KEY ,CountryId INT REFERENCES Countries ON DELETE CASCADE);
INSERT INTO Cities VALUES(1,1)
INSERT INTO Cities VALUES(2,1)
INSERT INTO Cities VALUES(3,2)CREATE TABLE Buyers(CustomerId INT PRIMARY KEY ,CityId INT REFERENCES Cities ON DELETE CASCADE);
INSERT INTO Buyers VALUES(1,1),
INSERT INTO Buyers VALUES(2,1)
INSERT INTO Buyers VALUES(3,2)此外还有级联更新
on update cascade
到此这篇关于SQL级联删除与级联更新的方法就介绍到这了。只有经历过地狱般的折磨,才有征服天堂的力量。只有流过血的手指才能弹出世间的绝唱。更多相关SQL级联删除与级联更新的方法内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!