在mysql中插入数据,会发现自增主键由于以前删除过纪录或者其他原因造成主键id不连续,如果需要连续的话必须使用AUTO_INCREMENT =1;
PS:
ALTER TABLE `table` AUTO_INCREMENT =1
执行之后,不一定再插入的id就是1;而是表中id最大值+1。
这是MySQL中的执行结果。
eg:
ALTER TABLE emp AUTO_INCREMENT=1; INSERT INTO emp(ename,job) VALUES('yangssss11ssss','laoshi') ;
每次执行两句一起。
到这里,问题就变的异常简单了:在每次插入之后都重置AUTO_INCREMENT的值。
如果插入的自定义函数或类的名称被定义成insert的话,那么就在此基础上扩展一个函数insert_continuous_id好了,其意为:保证自增主键连续的插入。