SQL Server 不会让你像这样级联,你需要使用触发器。这是一个如何进行删除的示例。如果您真的决定需要更新,则将更新留给读者作为练习。
Create Table AdjoiningStates (
State1ID int not null constraint FK_AdjoiningStates_States1 Foreign Key References States,
State2ID int not null constraint FK_AdjoiningStates_States2 Foreign Key References States,
Constraint PK_AdjoiningStates Primary Key (State1ID, State2ID)
)
Go
Create Trigger States_Delete On States Instead Of Delete As
Delete AdjoiningStates From AdjoiningStates a inner join deleted d on a.State1ID = d.StateID
Delete AdjoiningStates From AdjoiningStates a inner join deleted d on a.State2ID = d.StateID
Delete States From States s inner join deleted d on s.StateID = d.StateID
Go
在某些 SQL 版本上,如果这会成为瓶颈,那么在多次使用之前将已删除的表复制到临时表中会更有效。
示例小提琴