1. 创建一张表(name非空,age可空)
    2. [root@localhost][test]: create table user (name varchar(20) not null ,age int);
    3. Query OK, 0 rows affected (0.69 sec)
    4. 可以插入空字符串
    5. [root@localhost][test]: insert into user values('',19);
    6. Query OK, 1 row affected (0.05 sec)
    7. 插入空字符串,null
    8. [root@localhost][test]: insert into user values('',null);
    9. Query OK, 1 row affected (0.08 sec)
    10. 不能插入null
    11. [root@localhost][test]: insert into user values(null,null);
    12. ERROR 1048 (23000): Column 'name' cannot be null
    13. 查看字符串占用空间
    14. [root@localhost][test]: select length(name),length(age) from user where age is null;
    15. +--------------+-------------+
    16. | length(name) | length(age) |
    17. +--------------+-------------+
    18. | 0 | NULL |
    19. +--------------+-------------+
    20. 1 row in set (0.02 sec)
    21. 查看字符串长度
    22. [root@localhost][test]: select char_length(name),char_length(age) from user where age is null;
    23. +-------------------+------------------+
    24. | char_length(name) | char_length(age) |
    25. +-------------------+------------------+
    26. | 0 | NULL |
    27. +-------------------+------------------+
    28. 1 row in set (0.05 sec)
    29. 判断字符串是否为空,如果为空,则isnull(字段)=1
    30. [root@localhost][test]: select isnull(name),isnull(age) from user where age is null;
    31. +--------------+-------------+
    32. | isnull(name) | isnull(age) |
    33. +--------------+-------------+
    34. | 0 | 1 |
    35. +--------------+-------------+
    36. 1 row in set (0.00 sec)