MySQL表添加自增字段并指定起始

MySql无法像Access:以 20 起始且递增 10,把 autoincrement 改为 AUTOINCREMENT(20,10)

参考http://www.w3school.com.cn/sql/sql_autoincrement.asp


以下为MySql的解决方案:

创建表

create table student(
	a int not null,
	b int not null ,
	primary key (a)
);


添加自增字段,并指定起始10000:
ALTER table student 
add c int not null unique key auto_increment;

update student set c=c+'10000'; 

ALTER table student 
auto_increment=10000;

select * from student

插入数据试试:

insert into student (a,b) VALUES (100,1000);


你可能感兴趣的:(MySQL)