插入主键时出错
我正在尝试(SQL Server Compact)在其中包含一些行的现有表上添加主键约束。添加主键时出现错误:
“重复的键不能插入到唯一索引中”
我不知道这是什么,有人可以帮我解决这个问题吗?
I'm trying (SQL Server Compact) to add primary key constraint on existing table that has some rows in it. While adding primary key I'm getting the error:
"A duplicate key cannot be inserted into a unique index"
I don't what this is, can anyone help me with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保表中的数据符合您尝试在表上设置的约束。如果您要设置为主键的列有重复的条目,则它将无法用作主键,因此会出现错误。
您可以尝试查找具有重复条目的行,如下所示:
Make sure the data in the table respects the contraint you're trying to set on the table. If the column you are making primary has duplicate entries, it won't be able to work as primary key, hence the error.
You could try and find the rows with duplicate entries, with something like this:
尝试一下
如果上面的查询返回任何记录,则无法在 id_column 上添加主键,因为存在重复的 ID。
当然,您需要将
id_column
和your_table
替换为适当的名称。Try this
If there are any records returned from this above query you cannot add a primary key on
id_column
since duplicate IDs exist.Of course you will need to replace
id_column
andyour_table
with the appropriate names.