我有一个表actor
,其中有一个可为空的列first_name
。我将特定行设置为空:
update actor set first_name=null where actor_id=201;
Query OK, 1 rows affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
然后,我尝试使用 where 子句中的空值来查询该表,但什么也没得到:
select * from actor where first_name is null;
Empty set (0.00 sec)
但是如果我选择检查该列是否为空字符串,我会得到正确的值:
select * from actor where first_name = '';
[...]
1 row in set (0.00 sec)
存储引擎是MyISAM。为什么空列被设置为空字符串?
更新
我看到 1 个警告,但 mysql CLI 没有显示任何警告。我怎样才能让它这样做?
另外:
desc actor;
+-------------+----------------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+----------------------+------+-----+-------------------+-----------------------------+
| actor_id | smallint(5) unsigned | NO | PRI | NULL | auto_increment |
| first_name | varchar(45) | NO | | NULL | |
| last_name | varchar(45) | NO | MUL | NULL | |
| last_update | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+-------------+----------------------+------+-----+-------------------+-----------------------------+
最佳答案
从表描述来看,包括first_name在内的所有列都不为空。您确定它是可以为空的列吗?
关于mysql - 可空列的行为不一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44415005/