在为我的两个表(字符)和(派系)创建FOREIGN KEY时遇到问题。
让我解释一下情况:
一个角色通常有一个派系但有些可以有2个,所以(角色)表格有两列[Faction1]和[Faction2]都必须与(Factions)表相关。所以我制作了一个FOREIGN KEY(FK_Charachters(1)_Factions) 在删除时设置为空 级联更新
当我尝试制作FOREIGN KEY(FK_Charachters(2)_Factions),它将使用[Faction2]列而不是[Faction1]作为前一个键,并且 在删除时设置为空 级联更新
我收到错误消息:
“无法创建关系'FK_Characters(2)_Factions'。
在表'字符'上引入FOREIGN KEY约束'FK_Characters(2)_Factions'可能会导致循环或多个级联路径。指定ON DELETE NO ACTION或ON UPDATE NO ACTION,或修改其他FOREIGN KEY约束。“
当然,当我设置ON DELETE NO ACTION并且ON UPDATE NO ACTION一切正常但这将阻止派系的任何更新。
我可以做些什么来强制执行这2个FOREIGN KEY?
〜TIA〜 (人物)表
USE [HDA]
GO
/****** Object: Table [dbo].[Characters] Script Date: 05/15/2014 02:38:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Characters](
[ID] [smallint] IDENTITY(1,1) NOT NULL,
[CODE] [nvarchar](5) NULL,
[Name] [nvarchar](50) NULL,
[NameID] [smallint] NULL,
[Tier] [tinyint] NULL,
[Grp1] [tinyint] NULL,
[Grp2] [tinyint] NULL,
[Rarity] [tinyint] NULL,
[Fac1] [tinyint] NULL,
[Fac2] [tinyint] NULL,
[Speciality] [tinyint] NULL,
[MaxLevel] [smallint] NULL,
[Power] [smallint] NULL,
[HP] [smallint] NULL,
[Speed] [tinyint] NULL,
[Attack] [nvarchar](20) NULL,
[AttackDesc] [nvarchar](10) NULL,
[PowerPerLevel] [tinyint] NULL,
[HPPerLevel] [tinyint] NULL,
[TS] [timestamp] NULL,
[CreationDate] [datetime2](7) NOT NULL,
CONSTRAINT [PK_Characters] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Characters] WITH CHECK ADD CONSTRAINT [FK_Characters_AttackDescription] FOREIGN KEY([AttackDesc])
REFERENCES [dbo].[AttackDescription] ([ID])
GO
ALTER TABLE [dbo].[Characters] CHECK CONSTRAINT [FK_Characters_AttackDescription]
GO
ALTER TABLE [dbo].[Characters] WITH CHECK ADD CONSTRAINT [FK_Characters_CharactersName] FOREIGN KEY([NameID])
REFERENCES [dbo].[CharactersName] ([ID])
ON UPDATE CASCADE
ON DELETE SET NULL
GO
ALTER TABLE [dbo].[Characters] CHECK CONSTRAINT [FK_Characters_CharactersName]
GO
ALTER TABLE [dbo].[Characters] WITH CHECK ADD CONSTRAINT [FK_Characters_Rarity] FOREIGN KEY([Rarity])
REFERENCES [dbo].[Rarity] ([ID])
ON UPDATE CASCADE
ON DELETE SET NULL
GO
ALTER TABLE [dbo].[Characters] CHECK CONSTRAINT [FK_Characters_Rarity]
GO
ALTER TABLE [dbo].[Characters] ADD CONSTRAINT [DF__Character__Creat__395884C4] DEFAULT (sysdatetime()) FOR [CreationDate]
GO
(派系)表
USE [HDA]
GO
/****** Object: Table [dbo].[Factions] Script Date: 05/15/2014 02:42:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Factions](
[ID] [tinyint] NOT NULL,
[Color] [nvarchar](5) NOT NULL,
[Description] [ntext] NULL,
[TS] [timestamp] NULL,
[CreationDate] [datetime2](7) NOT NULL,
CONSTRAINT [PK_Factions] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[Factions] ADD CONSTRAINT [DF__Factions__Creati__4D5F7D71] DEFAULT (sysdatetime()) FOR [CreationDate]
GO