我正在創建一系列具有ddls表的數據庫,並且共有13個表。當我爲TBNSOR_VICTIM
表運行ddl時,出現外鍵約束錯誤。 ddl能夠創建第一個fk約束,但創建第二個fk約束時出現錯誤。有人可以幫我解決問題嗎?或者指出我在腳本中缺少什麼?這是錯誤時運行DDL腳本SQL Server 2008外鍵約束錯誤
消息1776,級別16,狀態0,2號線後得到
有在引用表「dbo.TBNSOR_OFFENSE」匹配,沒有主或候選鍵外鍵引用列列表「RD09RD03」
CREATE TABLE [dbo].[TBNSOR_OFFENSE](
[RD03_RC27SEQ_NBR] [int] NOT NULL,
[FK_RD01_RC17SID] [int] NOT NULL,
[RD03_RC27OFFENSE_DESC] [varchar] (100) NULL,
[RD03_STATUTE] [char](6) NULL,
[RD03_RC27PREDATOR_IND] [char] (1) NULL,
[RD03_RC27CONVICTION_DT] [date] NULL,
[RD03_RC27CONVICT_CITY] [varchar] (20) NULL,
[RD03_RC27CONVICT_STATE] [char] (2) NULL,
[RD03_RC27CONVICT_COUNTY] [varchar] (20) NULL,
[RD03_RC27CITY] [varchar] (20) NULL,
[RD03_RC27COUNTY] [varchar] (20) NULL,
[RD03_RC27OFFENSE_STATE] [char] (2) NULL,
[RD03_RC27OFFENSE_DATE] [date] NULL,
[RD03_RC27CONFIN_REL_DT] [date] NULL,
[RD03_RC27PP_RELEASE_DT] [date] NULL,
CONSTRAINT [CJ38ID03] PRIMARY KEY CLUSTERED
(
[RD03_RC27SEQ_NBR] ASC,
[FK_RD01_RC17SID] 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
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[TBNSOR_OFFENSE] WITH CHECK ADD CONSTRAINT [RD03RD01] FOREIGN KEY([FK_RD01_RC17SID])
REFERENCES [dbo].[TBNSOR_PHYSCSC] ([RD01_RC17SID])ON DELETE CASCADE
GO
ALTER TABLE [dbo].[TBNSOR_OFFENSE] CHECK CONSTRAINT [RD03RD01]
GO
CREATE TABLE [dbo].[TBNSOR_VICTIM](
[RD09_RC28SEQ_NUM] [int] NOT NULL,
[FK_RD01_RC17SID] [int] NOT NULL,
[FK_RD03_RC27SEQ_NBR] [int] NOT NULL,
[RD09_RC28SEX] [char] (1) NULL,
[RD09_RC28RACE] [char] (1) NULL,
[RD09_RC28AGE] [char](2) NULL,
[RD09_RC28HIGH_AGE] [char] (2) NULL,
[RD09_RC28LOW_AGE] [char] (2) NULL,
CONSTRAINT [CJ38ID09] PRIMARY KEY CLUSTERED
(
[RD09_RC28SEQ_NUM] ASC,
[FK_RD01_RC17SID] ASC,
[FK_RD03_RC27SEQ_NBR] 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
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[TBNSOR_VICTIM] WITH CHECK ADD CONSTRAINT [RD09RD01] FOREIGN KEY([FK_RD01_RC17SID])
REFERENCES [dbo].[TBNSOR_PHYSCSC] ([RD01_RC17SID])ON DELETE CASCADE
GO
ALTER TABLE [dbo].[TBNSOR_VICTIM] CHECK CONSTRAINT [RD09RD01]
GO
ALTER TABLE [dbo].[TBNSOR_VICTIM] WITH CHECK ADD CONSTRAINT [RD09RD03] FOREIGN KEY([FK_RD03_RC27SEQ_NBR])
REFERENCES [dbo].[TBNSOR_OFFENSE]([RD03_RC27SEQ_NBR])ON DELETE CASCADE
GO
ALTER TABLE [dbo].[TBNSOR_VICTIM] CHECK CONSTRAINT [RD09RD03]
GO
的可能重複的[SQL在參照表中沒有主或候選鍵(http://stackoverflow.com/questions/13095216/sql-no-primary-or-candidate-keys -in-the-referenced-table) – Pondlife 2013-03-06 20:07:26