Mysql 无法将tinyint和varchar字段更新为默认值null和空字符串
我有下表模式-Mysql 无法将tinyint和varchar字段更新为默认值null和空字符串,mysql,varchar,tinyint,Mysql,Varchar,Tinyint,我有下表模式- CREATE TABLE `tablename` ( `id` bigint(15) NOT NULL AUTO_INCREMENT, `uuid` varchar(400) NOT NULL, `pre_notif_action` varchar(30) DEFAULT '', `pre_notif_interval` tinyint(1) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `uuid_UNIQUE` (`
CREATE TABLE `tablename` (
`id` bigint(15) NOT NULL AUTO_INCREMENT,
`uuid` varchar(400) NOT NULL,
`pre_notif_action` varchar(30) DEFAULT '',
`pre_notif_interval` tinyint(1) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uuid_UNIQUE` (`uuid`),
) ENGINE=InnoDB DEFAULT CHARSET=latin1
对于现有记录,在pre_notif_action和pre_notif_interval字段中分别使用值“predeactivate”和45-
mysql> select pre_notif_action, pre_notif_interval
from tablename
where uuid="1887826113857166800";
结果-
+------------------+--------------------+
| pre_notif_action | pre_notif_interval |
+------------------+--------------------+
| predeactivate | 45 |
+------------------+--------------------+
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
当我尝试编辑时,会得到非零受影响的行-
update prepaid_account
set pre_notif_action=""
and pre_notif_interval=NULL
where uuid="1887826113857166800";
结果-
+------------------+--------------------+
| pre_notif_action | pre_notif_interval |
+------------------+--------------------+
| predeactivate | 45 |
+------------------+--------------------+
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
但是,当我选择-
mysql> select pre_notif_action, pre_notif_interval
from prepaid_account
where uuid="1887826113857166800";
我得到这个输出-
+------------------+--------------------+
| pre_notif_action | pre_notif_interval |
+------------------+--------------------+
| 0 | 45 |
+------------------+--------------------+
如何解决此问题?如果作为结果或逻辑操作,操作=0,则会得到预\u not:
pre_notif_action=""
and pre_notif_interval=NULL
返回0(false)
因此,您使用的是逻辑操作,而不是更新两列pre\u notif\u action
和pre\u notif\u interval
的设置
更新的多个列的正确语法是用逗号分隔的值,如下所示:
update prepaid_account
set pre_notif_action=""
, pre_notif_interval=NULL
where uuid="1887826113857166800";
如果作为结果或逻辑操作的\u action=0,则会得到pre\u not:
pre_notif_action=""
and pre_notif_interval=NULL
返回0(false)
因此,您使用的是逻辑操作,而不是更新两列pre\u notif\u action
和pre\u notif\u interval
的设置
更新的多个列的正确语法是用逗号分隔的值,如下所示:
update prepaid_account
set pre_notif_action=""
, pre_notif_interval=NULL
where uuid="1887826113857166800";
我认为这里的问题是SET子句中AND的使用。我认为你的问题是这样理解的:
update prepaid_account
set pre_notif_action = ("" and pre_notif_interval=NULL)
where uuid="1887826113857166800";
(“”和pre_notif_interval=NULL)
被解释为布尔值,这就是为什么0
被插入到字段中(0
相当于MySQL中的布尔值false
)。要解决此问题,请在SET子句中的多个字段之间使用逗号,如下所示:
update prepaid_account
set pre_notif_action = "", pre_notif_interval=NULL
where uuid="1887826113857166800";
我认为这里的问题是SET子句中AND的使用。我认为你的问题是这样理解的:
update prepaid_account
set pre_notif_action = ("" and pre_notif_interval=NULL)
where uuid="1887826113857166800";
(“”和pre_notif_interval=NULL)
被解释为布尔值,这就是为什么0
被插入到字段中(0
相当于MySQL中的布尔值false
)。要解决此问题,请在SET子句中的多个字段之间使用逗号,如下所示:
update prepaid_account
set pre_notif_action = "", pre_notif_interval=NULL
where uuid="1887826113857166800";
@MadhurBhaiya正在进行一些更新。这并不是说改变根本不适用,结果是一样的。为什么要使用单引号?如果要更改多个列,请使用逗号,而不是
SET
子句中的和。是的,您应该对字符串文字使用单引号。@MadhurBhaiya正在进行更新。这并不是说改变根本不适用,结果是一样的。为什么要使用单引号?如果要更改多个列,请使用逗号,而不是SET
子句中的和。是的,您应该对字符串文本使用单引号。