列属性问题
# 列属性问题
如果一个字段有 auto_increment
属性,则这个字段必须是 primary key
。
这样的字段在插入数据的时候可以填 null
,因为它是自增的。但是后续再这样插入数据的时候,auto_increment
不会再取已被删除的值。
mysql> insert into teacher values(null,'杨六',34,'2131231231','Shanghai');
1
mysql> select * from teacher;
+----+------+------+------------+----------+
| id | name | age | phone | address |
+----+------+------+------------+----------+
| 1 | 张三 | 32 | 1555555555 | NULL |
| 2 | 李四 | 25 | 2121212121 | 暂时未知 |
| 3 | 王五 | 56 | 4544 | Beijing |
| 4 | 杨六 | 34 | 2131231231 | Shanghai |
+----+------+------+------------+----------+
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
mysql> delete from teacher where id=3;
1
mysql> insert into teacher values(null,'童七',20,'1343434343',default);
1
+----+------+------+------------+----------+
| id | name | age | phone | address |
+----+------+------+------------+----------+
| 1 | 张三 | 32 | 1555555555 | 暂时未知 |
| 2 | 李四 | 25 | 2121212121 | 暂时未知 |
| 4 | 杨六 | 34 | 2131231231 | Shanghai |
| 5 | 童七 | 20 | 1343434343 | 暂时未知 |
+----+------+------+------------+----------+
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
编辑 (opens new window)
上次更新: 2022/09/26, 16:55:15