-----默认约束
-----就是当我们插入字段值的时候,没有传值,就会使用默认值
mysql> create table user10(
-> id int,
-> name varchar(20),
-> age int default 10
-> );
Query OK, 0 rows affected (0.08 sec)
mysql> desc user10;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| age | int | YES | | 10 | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.03 sec)
mysql>
mysql> insert into user10 (id,name) values (1,"zhangsan");
Query OK, 1 row affected (0.01 sec)
mysql> select * from user10;
+------+----------+------+
| id | name | age |
+------+----------+------+
| 1 | zhangsan | 10 |
+------+----------+------+
1 row in set (0.00 sec)
mysql>
mysql> insert into user10 values(2,"lisi",18);
Query OK, 1 row affected (0.00 sec)
mysql> select * from user10;
+------+----------+------+
| id | name | age |
+------+----------+------+
| 1 | zhangsan | 10 |
| 2 | lisi | 18 |
+------+----------+------+
2 rows in set (0.00 sec)
mysql>
---传了值,就不会使用默认值。