INSERT语句与FOREIGN KEY约束冲突.数据库中发生了冲突 [英] The INSERT statement conflicted with the FOREIGN KEY constraint. The conflict occurred in database

查看:725
本文介绍了INSERT语句与FOREIGN KEY约束冲突.数据库中发生了冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有两个小时了.在SQL Server中,我运行了此查询:

I have been having this problem for a couple of hours now. In SQL Server, I ran this query :

INSERT INTO USERS_AVATAR(userId, avatId) VALUES ('1', '213');
INSERT INTO USERS_AVATAR(userId, avatId) VALUES ('2', '312');

,但消息显示:

信息547,级别16,状态0,第1行
INSERT语句与FOREIGN KEY约束"FKUSERS_AVAT731248"冲突.在数据库"gk314"的表"gk314.USERS"的"userId"列中发生了冲突.

Msg 547, Level 16, State 0, Line 1
The INSERT statement conflicted with the FOREIGN KEY constraint "FKUSERS_AVAT731248". The conflict occurred in database "gk314", table "gk314.USERS", column 'userId'.

信息547,级别16,状态0,第2行
INSERT语句与FOREIGN KEY约束"FKUSERS_AVAT731248"冲突.在数据库"gk314"的表"gk314.USERS"的"userId"列中发生了冲突.

Msg 547, Level 16, State 0, Line 2
The INSERT statement conflicted with the FOREIGN KEY constraint "FKUSERS_AVAT731248". The conflict occurred in database "gk314", table "gk314.USERS", column 'userId'.

请帮助!

推荐答案

在将userIds 12插入USERS_AVATAR之前,必须首先将它们插入表USERS中.这就是FOREIGN KEY约束所需要的.

Before inserting userIds 1 and 2 into USERS_AVATAR, you must first insert them into table USERS. That is what the FOREIGN KEY constraint is requiring.

这篇关于INSERT语句与FOREIGN KEY约束冲突.数据库中发生了冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆