8:mysql奇怪的 NULL

给 user 表插入 null

insert into user values (666,'null',26);

 

新建一个 tmp 表

  1. create table tmp (
  2. id int,
  3. name char(10)
  4. );

 

插入记录

  1. insert into tmp values (1,'fujieace’),(2,null);

 

查询

  1. select * from tmp where name=null; //查不到数据
  2. select * from tmp where name !=null; //查不到数据
  3. select  null =null;  //有数据
  4. select null!=null; //有数据
  5. select * from tmp where name is null; //有数据
  6. select * from tmp where name is not null; //有数据

mysql null

注意事项:

1:null 比较特殊 , 它需要有自己专门的谓词来查 , 不便于优化 , 所以一半我们要尽量避免用 null

2:以上tmp表插入null值时,其实它的语法是不标准的,虽然说很多mysql数据库管理软件照样可以成功插入;但是不建议这样使用!

    A+
发布日期:2017年01月15日 19:29:43  所属分类:mysql教程
最后更新时间:2017-01-15 19:29:43
付杰
  • ¥ 129.0元
  • 市场价:199.0元
  • ¥ 999.0元
  • 市场价:1599.0元
  • ¥ 59.8元
  • 市场价:99.8元
  • ¥ 39.0元
  • 市场价:39.0元

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: