3

tsql で更新と削除の両方で制約を作成しようとしています。私はいくつかの異なる方法を試しましたが、今は少し行き詰まってイライラしています-とても簡単に思えます. 既存の制約を変更できないことはわかっているので、これを行う方法がわかりません。

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

またはこれ;

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

1 に答える 1

10

最初に制約を削除してから、再作成する必要があります。2 回目の試みは正しかったのですが、削除する必要がありました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
于 2012-07-13T10:56:00.640 に答える