INSERT语句与FOREIGN KEY约束冲突-SQL Server [英] INSERT statement conflicted with the FOREIGN KEY constraint - SQL Server
问题描述
我收到以下错误.你能帮我吗?
I am getting the following error. Could you please help me?
信息547,级别16,状态0,第1行
INSERT语句与FOREIGN KEY约束"FK_Sup_Item_Sup_Item_Cat"冲突.数据库"dev_bo"的表"dbo.Sup_Item_Cat"中发生了冲突.该声明已终止.
Msg 547, Level 16, State 0, Line 1
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Sup_Item_Sup_Item_Cat". The conflict occurred in database "dev_bo", table "dbo.Sup_Item_Cat". The statement has been terminated.
代码:
insert into sup_item (supplier_id, sup_item_id, name, sup_item_cat_id,
status_code, last_modified_user_id, last_modified_timestamp, client_id)
values (10162425, 10, 'jaiso', '123123',
'a', '12', '2010-12-12', '1062425')
最后一列client_id
导致错误.我试图将dbo.Sup_Item_Cat
中已经存在的值放入对应于sup_item的列中.
The last column client_id
is causing the error. I tried to put the value which already exists in the dbo.Sup_Item_Cat
into the column, corresponding to the sup_item.. but no joy :-(
推荐答案
在表dbo.Sup_Item_Cat
中,它具有对另一个表的外键引用. FK的工作方式是它不能在该列中拥有一个值,该值也不能在被引用表的主键列中.
In your table dbo.Sup_Item_Cat
, it has a foreign key reference to another table. The way a FK works is it cannot have a value in that column that is not also in the primary key column of the referenced table.
如果您具有SQL Server Management Studio,则将其打开并sp_help
'dbo.Sup_Item_Cat
'.查看FK所在的列,以及它引用的表的哪列.您正在插入一些错误数据.
If you have SQL Server Management Studio, open it up and sp_help
'dbo.Sup_Item_Cat
'. See which column that FK is on, and which column of which table it references. You're inserting some bad data.
让我知道您是否需要更好地解释!
Let me know if you need anything explained better!
这篇关于INSERT语句与FOREIGN KEY约束冲突-SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!