mysql设置主键自动增长

 

在Mysql中可以通过字段的auto_increment属性来自动增长。

1.不设置主键的增长起点(默认1开始)

create table user1(usernc varchar(10) not null,
                  userid int not null auto_increment,
                  username int not null,
                  sex varchar(10) not null,
                  idcard int(10) not null,
                  userpwd varchar(20) not null,
                  primary key(userid)
                  )
insert into user1(usernc,username,sex,idcard,userpwd)values("xiao","56","女","123456","llabc123");
insert into user1(usernc,username,sex,idcard,userpwd)values("xiao","2","女","123456","llabc123");

执行以上语句,数据表如下所示:

mysql设置主键自动增长_第1张图片

2.设置主键的增长起点(自己给定一个初始值)

create table user(usernc varchar(10) not null,
                  userid int not null auto_increment,
                  username int not null,
                  sex varchar(10) not null,
                  idcard int(10) not null,
                  userpwd varchar(20) not null,
                  primary key(userid)
                  )engine=INNODB auto_increment=316001;
insert into user(usernc,username,sex,idcard,userpwd)values("xiao","56","女","123456","llabc123");
insert into user(usernc,username,sex,idcard,userpwd)values("xiao","2","女","123456","llabc123");

mysql设置主键自动增长_第2张图片

你可能感兴趣的:(mysql设置主键自动增长)