给 user 表插入 null
insert into user values (666,'null',26);
新建一个 tmp 表
- create table tmp (
- id int,
- name char(10)
- );
插入记录
- insert into tmp values (1,'fujieace’),(2,null);
查询
- select * from tmp where name=null; //查不到数据
- select * from tmp where name !=null; //查不到数据
- select null =null; //有数据
- select null!=null; //有数据
- select * from tmp where name is null; //有数据
- select * from tmp where name is not null; //有数据
注意事项:
1:null 比较特殊 , 它需要有自己专门的谓词来查 , 不便于优化 , 所以一半我们要尽量避免用 null
2:以上tmp表插入null值时,其实它的语法是不标准的,虽然说很多mysql数据库管理软件照样可以成功插入;但是不建议这样使用!