2022年8月29日
在系统开发过程中,我们经常要用到唯一编号。使用过mysql的人都应该知道,mysql有一个定义列为自增的属性:AUTO_INCREMENT。
指定了AUTO_INCREMENT的列必须要建索引,不然会报错,索引可以为主键索引,当然也可以为非主键索引。(不一定要做主键)
1
2
3
mysql> create table t4 (id int auto_increment);
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
mysql>
下面的定义把t5表的主键定义为了name,而非自增的id字段
1
2
3
mysql>
mysql> create table t5 (id int au…