php - When the database inserts data, the automatically incremented primary key `id` does not increase in order.
为情所困
为情所困 2017-05-16 13:13:37
0
2
549

id=1 name=...
id=2
id=6
After deleting the records with IDs 3, 4, and 5 inserted before, why is it not 3, but to 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