php - 数据库在插入数据时,自动递增的主键`id`,没有按顺序递增
为情所困
为情所困 2017-05-16 13:13:37
0
2
513

id=1 name=...
id=2
id=6
在删除之前插入的id为3,4,5的记录后再插入为什么不是3,而是到6了

为情所困
为情所困

reply all(2)
为情所困

You will know why if you use the command.

show create table test2;

The self-increasing value will not be reduced when you delete the record.

 test2 | CREATE TABLE `test2` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `mouth` int(11) NOT NULL,
  `num` int(11) NOT NULL,
  PRIMARY KEY (`id`,`mouth`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=gbk

If you want to modify the self-increment value, please use sql to modify it

 alter table test2 auto_increment=4;

The modified primary key auto-increment starting point.

  test2 | CREATE TABLE `test2` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `mouth` int(11) NOT NULL,
  `num` int(11) NOT NULL,
  PRIMARY KEY (`id`,`mouth`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=gbk |
大家讲道理

You can refer to mysql auto-increment here, if you want that id 继续从3开始就要手动 INSERT INTO (id,字段2,字段2) VALUES ('3',值1,值2)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!