INSERT语句与FOREIGN KEY约束冲突.数据库中发生了冲突 [英] The INSERT statement conflicted with the FOREIGN KEY constraint. The conflict occurred in database
问题描述
我已经有两个小时了.在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 1
和2
插入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屋!