插入语句与FK约束冲突 [英] Insert statement conflicts with FK constraint

查看:108
本文介绍了插入语句与FK约束冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候......



我有两个SQL Server,EMP和ID表。

EMP有一般信息,如姓名,性别,电话,地址,....

和ID有身份证号码和其他信息。

我在主键之间建立了一对一的关系这两个表。



ID表允许插入命令,但EMP表不能

和显示此消息

插入语句与FK约束冲突并说明关系和外键的名称。



为什么会这样?谢谢大家





PS:

1-两个表的主键是同一个名字ID

2-与无动作关系完整性的关系。

3-两个表的主键是int auto increment

4- EMP表与其他表有其他1对1和1到M的关系

解决方案

阅读本文以了解根本原因:

1. FOREIGN KEY Constraints [< a href =http://technet.microsoft.com/en-us/library/ms175464%28v=sql.105%29.aspxtarget =_ blanktitle =New Window> ^ ]

2. SQL FOREIGN KEY Constraint [ ^ ]


这是解释...



错误消息:INSERT语句与FOREIGN KEY约束冲突 [ ^ ]

Greetings ...

I have two Tables in SQL Server, EMP and IDs.
EMP has general information like name, gender, phone, address, ... .
and IDs has Numbers of Identification cards and other information about them.
I have made One to One relationship between primary keys of the two tables.

The IDs table allows Insert command, but The EMP table DOES NOT.
and shows this message
"Insert statement conflicts with FK constraint" and states the names of the relation and the foreign keys.

Why is that happened ?? Thank u all


P.S:
1- The Primary keys for the two tables are the same name "ID"
2- The Relationship with "no action" relational integrity.
3- The Primary keys for the both of the tables are int auto increment
4- the EMP table has other 1 to 1 and 1 to M relationships with other tables

解决方案

Read this to understand the root cause:
1. FOREIGN KEY Constraints[^]
2. SQL FOREIGN KEY Constraint[^]


Here is the Explanation...

Error Message: The INSERT statement conflicted with the FOREIGN KEY constraint[^]


这篇关于插入语句与FK约束冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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