[英]When inserting data, Insert statement conflicted with the Foreign Key constraint
我有一个名为Book_details的表,它有一个主键作为Bid ,现在这个BID也是同一数据库中其他两个表的外键(即slend_details,Book_inventory)
当我将数据插入inventory_details表时,我收到以下错误:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__book_invent__Bid__1367E606". The conflict occurred in database "library_management", table "dbo.Book_details", column 'Bid'.
The statement has been terminated.
这是我使用的插入语句:
insert into Book_inventory (Bid, present) values (001,1)
这是我用于book_inventory表的create语句:
create table book_inventory (
Bid varchar(50) Not null Foreign Key references Book_details(Bid),
present bit Not null*
)
我甚至检查了值,即我试图在book_inventory表中输入的数据出现在Book_details表中。 我仍然得到错误。 有人可以帮我吗?
你的插入;
insert into Book_inventory (Bid,present) values (001,1)
将Bid
作为整数插入,这很可能意味着它将值简化为1
,而不是作为Bid
存在。
引用该值并将其作为实际字符串插入应该可以正常工作;
insert into Book_inventory (Bid,present) values ('001',1)
Bid是varchar,您将其用作整数。 试试这个查询
insert into Book_inventory (Bid, present) values ('001',1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.