1.空间占用测试
mysql> select length(NULL), length(''), length('NULL');
+--------------+------------+-------------+
| length(NULL) | length('') | length('1') |
+--------------+------------+-------------+
| NULL | 0 | 4 |
+--------------+------------+-------------+
1 row in set (0.03 sec)
注:空串是不占用存储空间的
2.实战
-- 创建表
create table tb_test_1(
id int unsigned primary key auto_increment, --自增
one varchar(10) NOT NULL,
two varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- 字符集格式
create table tb_test_2(
id int unsigned primary key auto_increment,
one varchar(10) NOT NULL,
two varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- 模拟数据
insert into tb_test_1(one,two) values (1,NULL);
insert into tb_test_1(one,two) values (2,'');
insert into tb_test_1(one,two) values (2,"NULL");
insert into tb_test_1(one,two) values (3,3);
insert into tb_test_2(one,two) values (4,NULL);
insert into tb_test_2(one,two) values (4,'');
insert into tb_test_2(one,two) values (5,"NULL");
insert into tb_test_2(one,two) values (6,3);
执行结果:
?
注:
? ? ? ? ?1.??== 如果要单纯查NULL值列,则使用?is NULL 去查,单纯去查空值('')列,则使用?='’
? ? 2. 其他可以关联包括空串,但null不能
? ? 3. count(字段)不会统计null值,count(*)可以 ?
|