我在表中有以下数据
name price
red wine 150
white wine 300
我想删除值300
我使用了下面的查询
update cms.wine set price =null where name='white wine'
它给了我下面的错误
You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Queries and reconnect.
最佳答案
这样做:
SET SQL_SAFE_UPDATES=0;
然后:
update cms.wine set price =null where name='white wine;'
但是你应该在 id 列的基础上做,因为它会删除所有名称等于 white wine
的记录像这样:
update cms.wine set price =null where id=1;
在此它将仅删除主键值为 1 的特定记录。
您应该在表中添加一个主键列,以便您的表看起来像这样,并使该列成为主键,以便它对于每条记录始终是唯一的:
id name price
1 red wine 150
2 white wine 300
关于c# - 如何从mysql表中删除单个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23076961/