无法在具有唯一索引的对象'dbo.CFD'中插入重复的键行

时间:2015-03-18 14:26:35

标签: sql-server indexing key

我在将一行插入表dbo.CFD时遇到错误。完整的错误说明:

无法在对象' dbo.CFD'中插入重复的关键行具有唯一索引' IX_CFD_NRSC_FXTR_N'。重复键值为(BP2001,1990,CHK,01,3 3456)。

查看相关索引IX_CFD_NRSC_FXTR_N,它是单个列上的非唯一非聚集索引(错误中包含BP2001的列)。

查看数据,有许多记录的BP2001,CHK,01和3456的值,但没有1990年(但各种其他值),所以它似乎并没有与一个独特的冲突约束

我还验证了所有外键约束都得到了满足,并且没有违反主键约束。

如何确定导致此问题的确切原因?我可以找到的每个例子都会导致插入重复数据,但我不认为这是问题所在。谢谢!

编辑----------

表创建脚本:

CREATE TABLE [dbo].[CFD](
    [PRPSL_I] [int] NOT NULL,
    [FILE_TYPE_C] [char](3) NOT NULL,
    [CAD_FLR_C] [char](2) NOT NULL,
    [FXTR_SERL_I] [int] NOT NULL,
    [ADJC_I] [int] NULL,
    [CMP_I] [int] NULL,
    [VER_I] [int] NULL,
    [NRSC_FXTR_N] [varchar](15) NULL,
    [MDSE_SPCE_HT_I] [int] NULL,
    [MDSE_SPCE_LGTH_I] [int] NULL,
    [MDSE_SPCE_DPT_I] [int] NULL,
    [NRSC_FXTR_SIDE_I] [int] NULL,
    [NRSC_FXTR_SECT_I] [int] NULL,
    [BOFM_INCL_F] [bit] NOT NULL,
    [DIVI_I] [int] NULL,
    [PRTY_I] [int] NULL,
    [REUSE_I] [int] NULL,
    [FXTR_ISTL_LOC_N] [varchar](6) NULL,
    [PHYS_SECT_NUM_I] [int] NULL,
    [SAFL_LOC_N] [varchar](4) NULL,
    [SEQ_I] [int] NULL,
    [SIDE_ASLE_I] [int] NULL,
    [LDIN_I] [int] NULL,
    [LDIN_STAT_I] [int] NULL,
 CONSTRAINT [PK_CFD] PRIMARY KEY CLUSTERED 
(
    [PRPSL_I] ASC,
    [FILE_TYPE_C] ASC,
    [CAD_FLR_C] ASC,
    [FXTR_SERL_I] ASC
)WITH (PAD_INDEX = ON, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[CFD] ADD  CONSTRAINT [DF_CFD_BOFM_INCL_F]  DEFAULT ((0)) FOR [BOFM_INCL_F]
GO

ALTER TABLE [dbo].[CFD]  WITH CHECK ADD  CONSTRAINT [FK1_CFD] FOREIGN KEY([PRPSL_I], [FILE_TYPE_C], [CAD_FLR_C])
REFERENCES [dbo].[CAD_FILE] ([PRPSL_I], [FILE_TYPE_C], [CAD_FLR_C])
GO

ALTER TABLE [dbo].[CFD] CHECK CONSTRAINT [FK1_CFD]
GO

ALTER TABLE [dbo].[CFD]  WITH CHECK ADD  CONSTRAINT [FK2_CFD] FOREIGN KEY([CMP_I])
REFERENCES [dbo].[CMP] ([CMP_I])
GO

ALTER TABLE [dbo].[CFD] CHECK CONSTRAINT [FK2_CFD]
GO

ALTER TABLE [dbo].[CFD]  WITH CHECK ADD  CONSTRAINT [FK3_CFD] FOREIGN KEY([ADJC_I])
REFERENCES [dbo].[ADJC_E] ([ADJC_I])
GO

ALTER TABLE [dbo].[CFD] CHECK CONSTRAINT [FK3_CFD]
GO

ALTER TABLE [dbo].[CFD]  WITH CHECK ADD  CONSTRAINT [CK_CFD] CHECK  (([FILE_TYPE_C]<>'SFP'))
GO

ALTER TABLE [dbo].[CFD] CHECK CONSTRAINT [CK_CFD]
GO



CREATE NONCLUSTERED INDEX [IX_CFD_NRSC_FXTR_N] ON [dbo].[CFD]
(
    [NRSC_FXTR_N] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

0 个答案:

没有答案