INSERT语句与FOREIGN KEY约束FK__ProductSa__Clien__56B3DD81冲突。冲突发生在数据库ReportSystem,表StarBazar.ClientDetails,列''ClientId''。 该声明已被终止。 帮我解决这个问题。When I execute the procedure, it gives the following error.insert into [StarBazar].[ProductSale](ProductId,C_Id,Quantity,DateOfSale) values(1,1,1,''2015-06-25 10:30:35.0210666'') (1 row(s) affected)Msg 547, Level 16, State 0, Line 3The INSERT statement conflicted with the FOREIGN KEY constraint "FK__ProductSa__Clien__56B3DD81". The conflict occurred in database "ReportSystem", table "StarBazar.ClientDetails", column ''ClientId''.The statement has been terminated.Help me to solve this.推荐答案首先要插入 usp_InsertProductSale 表的forienkey引用值,所以它给出了一个例外。 必须确认ProductId和C_Id存在于 usp_InsertProductSale 表中。 如果不存在然后你必须先在 usp_InsertProductSale 中插入它,然后只有你可以在 ProductSale > table。You are inserting forienkey reference value of a usp_InsertProductSale table first,so it gives an exception.Must confirm ProductId and C_Id is exists in usp_InsertProductSale table.if not exists then you have to first insert it in usp_InsertProductSale then only you can insert itin ProductSale table.外键是对不同表中唯一值的引用,SQL将确保引用完整性 - 这意味着它不会让你以孤儿的关键参考。向外键列插入值时,它必须是null或对另一个表中的行的现有引用,并且在删除时,必须首先删除包含外键的行,然后删除它引用的行。 br /> 如果你不是,你会收到一个错误,比如你所描述的。 所以输入首先进入主表的行,然后输入依赖表信息第二。A foreign key is a reference to a unique value in a different table, and SQL will ensure "referential integrity" - which means it won''t let you end you with "orphaned" key references. When you insert a value to a foreign key column it must be a null or a existing reference to a row in the other table, and when you delete, you must delete the row containing the foreign key first, then the row it references.If you don''t, you will get an error such as you describe.So enter the row into the "main" table first, then enter the "dependant" table information second. 这篇关于insert语句与外键约束冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-13 06:12