一連のテーブル ddls を使用してデータベースを作成していますが、全部で 13 個のテーブルがあります。テーブルの ddl を実行すると、外部キー制約エラーが発生しTBNSOR_VICTIM
ます。ddl は最初の fk 制約を作成できましたが、2 番目の fk 制約を作成するとエラーが発生します。誰かが私を助けたり、スクリプトに欠けているものを教えてくれませんか? これは、ddl スクリプトを実行した後に発生するエラーです。
メッセージ 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