INSERT statement conflicted with the FOREIGN KEY constraint - SQL Server(INSERT 语句与 FOREIGN KEY 约束冲突 - 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:INSERT 语句与 FOREIGN KEY 约束冲突 - SQL Server
基础教程推荐
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01