复制代码代码如下:ondeletecascade当你更新或删除主键表时,那么外键表也会跟随一起更新或删除,需要在建表时设置级联属性CREATETABLECountries(CountryIdINTPRIMARYKEY)INSERTINTOCountries(CountryId)VALUES(1)INSERTINTOCountries(CountryId)VALUES(2)INSERTINTOCountries(CountryId)VALUES(3)CREATETABLECities(CityIdINTPRIMARYKEY ,CountryIdINTREFERENCESCountriesONDELETECASCADE);INSERTINTOCitiesVALUES(1,1)INSERTINTOCitiesVALUES(2,1)INSERTINTOCitiesVALUES(3,2)CREATETABLEBuyers(CustomerIdINTPRIMARYKEY,CityIdINTREFERENCESCitiesONDELETECASCADE);INSERTINTOBuyers&
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
声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!