且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

TSQL 更改表为删除和更新的级联添加约束

更新时间:2023-02-05 13:32:05

您需要先删除约束,然后重新创建它.您的第二次尝试是正确的,但您需要删除 .

You need to drop constraint first, and then recreate it. Your second attempt was right, but you needed to remove and.

alter table AllowedCars 
  drop constraint FK_AllowedCars_CarID 

alter table AllowedCars 
  add constraint FK_AllowedCars_CarID 
      foreign key (CarID) 
      references Cars(CarID) 
      on delete cascade 
      on update cascade