设置自增id
通常的设置自增字段的方法:
创建表格时添加:
create table table1(id int auto_increment primary key,…)
创建表格后添加:
alter table table1 add id int auto_increment primary key 自增字段
一定要设置为primary key.
希望table中数据的id不要从1开始 id从100开始,代码如下:
alter table users AUTO_INCREMENT=100;
本文介绍如何在MySQL中设置自增ID,包括在创建表格时和创建后添加自增字段的方法,以及如何设定自增ID的起始值。
2567





