我创建了两个表,客户和记录。Records 对 customerID 有一个外键约束。当我尝试向已经存在的客户插入记录时,它给了我这个错误:
Message (The INSERT statement conflicted with the FOREIGN KEY constraint "FK_REC_cstmr_int_id". The conflict occurred in database "Omitted", table "dbo.CST_NEW_CUSTOMER", column 'cstmr_int_id'.)
这是插入代码:
INSERT INTO [Omitted].[dbo].[REC_NEW_RECORDS]
([cstmr_int_id]
,[xml_tx]
VALUES
(10
,'<test>test</test>'
GO
我在这里找到的大多数相关问题都涉及以错误的顺序插入,但我可以选择 id 为 10 的客户。任何指针将不胜感激。
编辑 1:这将返回一位客户
SELECT [cstmr_int_id]
FROM [Omitted].[dbo].[CST_NEW_CUSTOMER] WHERE cstmr_int_id =10
编辑2:这是记录表的创建脚本
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[REC_NEW_RECORDS](
[rec_int_id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[cstmr_int_id] [int] NOT NULL,
[xml_tx] [varchar](max) NULL,
CONSTRAINT [REC_PK_rec_int_id] PRIMARY KEY CLUSTERED
(
[rec_int_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]
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[REC_NEW_RECORDS] WITH CHECK ADD CONSTRAINT [FK_REC_cstmr_int_id] FOREIGN KEY([cstmr_int_id])
REFERENCES [dbo].[CST_NEW_CUSTOMER] ([cstmr_int_id])
GO