这是我的Visual Studio 2015项目中的两个表 表1:
CREATE TABLE [dbo].[Player] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[First_Name] NVARCHAR (50) NULL,
[Last_Name] NVARCHAR (50) NULL,
[Nickname] NVARCHAR (50) NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
和表2:
CREATE TABLE [dbo].[Match] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Time] TIME (7) NULL,
[Winner_Id] INT NOT NULL,
[Loser_Id] INT NOT NULL,
[Tournament_Id] INT NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_Player_Winner] FOREIGN KEY ([Winner_Id]) REFERENCES [dbo].[Player] ([Id]),
CONSTRAINT [FK_Player_Loser] FOREIGN KEY ([Loser_Id]) REFERENCES [dbo].[Player] ([Id]),
CONSTRAINT [FK_Match_Tournament] FOREIGN KEY ([Tournament_Id]) REFERENCES [dbo].[Tournament] ([Id])
);
我想要的是在Match表中的外键上添加ON DELETE CASCADE
,但是我无法在播放器外键上创建删除级联。我希望能够做到这一点,因为如果一名球员被删除,我希望他所参加的所有比赛都被删除,无论是作为胜利者还是作为失败者。我的备份解决方案是在Match中添加一个包含" forfeit"值,因此不计算与此标志的匹配。删除播放器时可以设置此标志。知道如何实现这个吗?