sql插入语句怎么设置表中的一列于自动增长列一样

如题所述

1. 如果该字段不是主键,需要先设置该字段为主键:
alter table 表名 add primary key(字段名);
2. 修改字段为自动增长
alter table 表名 change 字段名 字段名 字段类型 auto_increment;
下面是完整例子:
1.create table student(id int);
2.alter table student add primary key(id);
3.alter table student change id id int auto_increment;
mysql测试过,可以这样做,其他数据库应该也可以。
温馨提示:答案为网友推荐,仅供参考
相似回答