忽略索引上的重复值可防止外键约束
由于某些架构原因,我必须忽略索引上的重复值。它工作得很好 - 除非我插入错误的数据。我正在尝试将值插入到应该抛出的 FK 列中:
INSERT 语句与 FOREIGN KEY 约束“FK__constrainName”冲突。
冲突发生在数据库表“someTable”、列“FKColumn”中。
忽略重复值背后是否存在阻止插入语句抛出此异常的逻辑?
Due to some architectural reasons I have to ignore duplicate values on the index. It works perfectly well - except, when I am inserting wrong data. I am trying to insert value to the FK column that is supposed to throw:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__constrainName".
The conflict occurred in database, table "someTable", column 'FKColumn'.
Is there logic behind ignoring duplicate values that prevents insert statement from throwing this exception?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜你说的是这种情况?
如果未插入一行,因为它会导致重复键冲突,则插入后不会违反 FK 约束,因此不会出现错误。
I assume you are talking about this kind of situation?
If a row is not inserted because it would cause a duplicate key violation then the FK constraint is not violated following the insert, hence no error.