查询以在 MySQL 中切换布尔值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4912946/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:38:51  来源:igfitidea点击:

Query to toggle boolean value in MySQL

mysql

提问by Santosh Linkha

Possible Duplicate:
Is there a way in MySQL to reverse a boolean field with one query?

可能的重复:
MySQL 中是否有一种方法可以通过一个查询来反转布尔字段?

To update (boolean) value normally we would check if it's set to false or true, and update it, I was wondering if there's query that would toggle boolean value.

为了正常更新(布尔)值,我们会检查它是否设置为 false 或 true,然后更新它,我想知道是否有查询可以切换布尔值。

回答by zerkms

UPDATE mytbl
   SET field = !field
 WHERE id = 42

Where 42is the idof the record, fieldis the name of the boolean field and mytblis the table name.

哪里42id记录的,field是布尔字段的名称,mytbl是表名。

回答by XMen

You can use Boolean Operator for this Here delete is your boolean field.

您可以为此使用布尔运算符 这里删除是您的布尔字段。

update tab set `delete`=NOT `delete`