---非空约束 ---修饰的字段不能为空NULL mysql> create table user9( -> id int, -> name varchar(20) not null -> ); Query OK, 0 rows affected (0.01 sec) mysql> desc user9; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | id | int | YES | | NULL | | | name | varchar(20) | NO | | NULL | | +-------+-------------+------+-----+---------+-------+ 2 rows in set (0.00 sec) mysql> mysql> insert into user9 (id) values (1); ERROR 1364 (HY000): Field 'name' doesn't have a default value mysql> mysql> insert into user9 (id) values (1); ERROR 1364 (HY000): Field 'name' doesn't have a default value mysql> insert into user9 values(1,"zhangsan"); Query OK, 1 row affected (0.00 sec) mysql> desc user9; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | id | int | YES | | NULL | | | name | varchar(20) | NO | | NULL | | +-------+-------------+------+-----+---------+-------+ 2 rows in set (0.00 sec) mysql> select * from user9; +------+----------+ | id | name | +------+----------+ | 1 | zhangsan | +------+----------+ 1 row in set (0.00 sec) mysql> ---再举个例子: mysql> create table user66( -> id int not null, -> name varchar(20) -> ); Query OK, 0 rows affected (0.01 sec) mysql> desc user66; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | id | int | NO | | NULL | | | name | varchar(20) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ 2 rows in set (0.01 sec) mysql> insert into user66(name) values("zhangsan"); ERROR 1364 (HY000): Field 'id' doesn't have a default value mysql> mysql> insert into user66(id) values("9"); Query OK, 1 row affected (0.00 sec) mysql> select * from user66; +----+------+ | id | name | +----+------+ | 9 | NULL | +----+------+ 1 row in set (0.00 sec) mysql>