先回顾下mybatis中设置主键自增的方法
mysql
<insert id="xxx" useGeneratedKeys="true" keyProperty="id">
insert into tb(a,b,c) values(#{a},#{b},#{c})
</insert>
//oracle使用序列
<insert id="xxx">
<selectKey keyProperty="id" order="BEFORE" resultType="Integer">
select xxx_SEQ.nextval from dual
</selectKey>
insert into tb(id,a,b,c) values(#{id},#{a},#{b},#{c})
</insert>
useGeneratedKeys="true" 设置使用自增主键;
keyProperty="id" 设置自增主键返回字段(用户在插入数据之后获取相应主键);
order="BEFORE" 设置在insert之前执行查询序列操作,然后在insert时候引用查询的序列#{id}
如果删除掉其中的某部分数据,就会发现主键出现断续的情况,后续添加的数据主键只会在最大处往后累加,这不仅让数据不连续,而且主键会越来越大,达到一定程度可能int类型会装不下了....
处理办法:
1.删除主键
alter table aead_campaign_google drop id
2.创建非空字段id
ALTER TABLE `aead_campaign_google` ADD `id` int NOT NULL FIRST;
3.将id设置成自增主键
ALTER TABLE `aead_campaign_google` MODIFY COLUMN `id` int NOT NULL AUTO_INCREMENT,ADD PRIMARY KEY(id);
这样主键会重新排序,之前因为删除的空缺部分也会被填补完毕