c# - 如何从mysql表中删除单个值

标签 c# mysql winforms

我在表中有以下数据

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/

相关文章:

winforms - 创建一个允许拖放自定义 'widgets'的winforms应用程序

vb.net - Form.ShowDialog() 不显示表单

c# - 在 C# 中的标签中显示全文

c# - 使用 Xamarin C# 创建可绑定(bind)属性没有属性,找到可绑定(bind)属性

c# - 注销主窗体并显示登录窗体

c# - 任何人都可以制作假证书吗?

php - 在另一个字符串中的某个单词之前插入字符串

c# - 为什么 WebApi 帮助页面中不显示操作

mysql - NodeJS + ExpressJS 管理与 mysql 数据库连接的正确方法

php - 多维 PHP 数组保持为空