前提,需保证设置了自增:
alter table table1 add id int auto_increment primary key
方式1,修改现有自增ID:
alter table users AUTO_INCREMENT=10000;
方式2,建表时指定:
CREATE TABLE TABLE_1 ( ID INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, // ID列为无符号整型,该列值不可以为空,并不可以重复,而且自增。 NAME VARCHAR(5) NOT NULL ) AUTO_INCREMENT = 100;(ID列从100开始自增)
方式3,从默认值开始:
TRUNCATE TABLE table1
两步
1.sql重设全部数据的id
update table t
set t.id = (
select @n := @n + 1 from (SELECT @n := 10000) r
)
2.重设表自增长起始位置
alter table users AUTO_INCREMENT=10001
UPDATE 【table】 SET id=id+3999;