这个陈述中的错误是什么 [英] What is the error in this statement

查看:78
本文介绍了这个陈述中的错误是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

create table foreign_2
( id int,
age int,
ph_no int
foreign key(id) references foreign_1(id)
on delete cascade on update set null
);

insert into foreign_2 values(1,18,8988477);
insert into foreign_2 values(2,15,8988477);
insert into foreign_2 values(3,12,1098777);
insert into foreign_2 values(4,10,225555477);
insert into foreign_2 values(5,17,87525483);





此查询未完成为什么?

发生错误...

消息547,等级16,状态0,行1

INSERT语句与FOREIGN KEY约束FK__foreign_2__ph_no__3D491139。冲突发生在数据库master,表dbo.foreign_1,列'id'。

声明已被终止。



我的尝试:



i试图在foreign_2表中插入数据



this query is not completed why?
an error occured that...
Msg 547, Level 16, State 0, Line 1
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__foreign_2__ph_no__3D491139". The conflict occurred in database "master", table "dbo.foreign_1", column 'id'.
The statement has been terminated.

What I have tried:

i tried to insert the data in the foreign_2 table

推荐答案

错误非常明确:

The error is pretty explicit:
The INSERT statement conflicted with the FOREIGN KEY constraint

这是什么意思,你试过的sis在表中(特别是在id列中)插入一个值,该值在另一个表的匹配列中不存在(具体地说,是foreign_1表的ID列)。

你可以'这样做:外键意味着此表与该表相关 - 并且您不能创建在另一个表的列中没有匹配值的行。

What that mean sis that you tried to insert a value into your table (specifically into the id column) which doesn't exist in the matching column in the other table (specifically, the ID column of the foreign_1 table).
You can't do that: a foreign key means "this table is related to that table" - and you can't create a row which doesn't have matching value in the column of the other table.


这篇关于这个陈述中的错误是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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