如何修复“违反PRIMARY KEY约束”错误? [英] How to fix "Violation of PRIMARY KEY constraint" error?

查看:1598
本文介绍了如何修复“违反PRIMARY KEY约束”错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个功能:

I have two function:

展开 | 选择 | Wrap | 行号

推荐答案

你放一个主键对表QUESTIONARIO1的字段USER的约束。主键上不能有重复值。如果你需要重复,那么你必须删除主键。
You put a primary key constraint on the field USER for the table QUESTIONARIO1. You can''t have duplicate values on a primary key. If you need to have duplicates, then you have to remove the primary key.


是的,当然。但我测试我想插入的键是否与函数TestExistingRow是唯一的 - 正如你所看到的 - 它返回给我false,即使然后应用程序得到错误。这种情况有时只会发生,并非总是如此。


函数TestExistingRow计算同一个表中存在多少条记录,其中包含我想要插入的键,如果数字的话,则返回FALSE row为0(零)。 AddData函数然后尝试仅在第一个(TestExistingRow)返回false时插入密钥。所以...为什么有时它会返回假,但后来我得到了违反主要密钥。错误?


但是,感谢您的关注! :)
Yes, of course. But I test if the key i want to insert is unique with the function TestExistingRow - as you can see - and it returns to me false, even if then the application gets the error. This situation occures only sometimes, not always.

The function TestExistingRow counts how many records are existing in the same table with the key that i want to insert and return FALSE ONLY if the numer of row is 0 (zero). The "AddData" function then tries to insert the key ONLY IF the first one (TestExistingRow) return false. So...why sometimes it return false but then i get the "VIOLATION OF PRIMARY KEY" error?

However, Thanks for your attention! :)


你检查了表本身吗?您应该打印出SQL insert命令并检查表本身。该表上主键的定义是什么?它是复合键吗?
Have you checked the table itself? You should have it print out the SQL insert command and check the table itself. What is the definition of the primary key on that table? Is it a compound key?


这篇关于如何修复“违反PRIMARY KEY约束”错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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