SQL 更新或删除的行值要么不会使行唯一,要么会改变多行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36859306/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
the row values updated or deleted either do not make the row unique or they alter multiple rows
提问by Zumm
回答by Akshey Bhat
There are duplicate rows in your table. When this is the case you cannot edit table using UI. first delete rows with matching data using SQL then try and edit. Delete rows with matching data one by one until you are left with one row. Use the following query for deleting matching rows where column IdSeminar has value 1 :
您的表中有重复的行。在这种情况下,您无法使用 UI 编辑表格。首先使用 SQL 删除具有匹配数据的行,然后尝试编辑。一一删除具有匹配数据的行,直到只剩下一行。使用以下查询删除 IdSeminar 列值为 1 的匹配行:
Delete top(1) from tab where IdSeminar=1
do the same with other matching rows.
对其他匹配行执行相同操作。
回答by Serg
SQL Studio cautiously tries to delete exactly one row but finds no way to identify it. Contrary to what it's UI may tempt you to suppose, row can't be identified by it's position in the result set.
SQL Studio 小心地尝试只删除一行,但找不到识别它的方法。与它的 UI 可能会诱使您假设的相反,无法通过它在结果集中的位置来识别行。
回答by Scanner
This might be a bit late but it could help someone. I ran into the same issue today but Akshey's code didn't work for me. My database table didn't contain an ID column, so I added one in and set it's 'Identity Specification' to 'Yes'. I reloaded the table with this new column in it and then was able to delete whichever rows I wanted. Afterwards I deleted the ID column, reloaded and the table and everything was fine.
这可能有点晚了,但它可以帮助某人。我今天遇到了同样的问题,但 Akshey 的代码对我不起作用。我的数据库表不包含 ID 列,因此我添加了一个并将其“身份规范”设置为“是”。我用这个新列重新加载了表格,然后能够删除我想要的任何行。之后我删除了 ID 列,重新加载了表格,一切都很好。