主鍵自增出現間斷問題解決辦法

2021-09-27 01:25:14 字數 805 閱讀 7453

先回顧下mybatis中設定主鍵自增的方法

mysql

insert into tb(a,b,c) values(#,#,#)

//oracle使用序列

select ***_seq.nextval from dual

insert into tb(id,a,b,c) values(#,#,#,#) 

usegeneratedkeys="true" 設定使用自增主鍵;

keyproperty="id"  設定自增主鍵返回字段(使用者在插入資料之後獲取相應主鍵);

order="before"  設定在insert之前執行查詢序列操作,然後在insert時候引用查詢的序列#

如果刪除掉其中的某部分資料,就會發現主鍵出現斷續的情況,後續新增的資料主鍵只會在最大處往後累加,這不僅讓資料不連續,而且主鍵會越來越大,達到一定程度可能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);

這樣主鍵會重新排序,之前因為刪除的空缺部分也會被填補完畢

Oracle主鍵自增的解決辦法

首先,要建立乙個表 create table userinfo userid int not null primary key,username varchar 20 not null,password varchar 20 not null,varchar 4 age int 然後,建立乙個序列 ...

dpkg install 出現問題解決辦法

dpkg 處理軟體包 gir1.2 unity 5.0 amd64 configure 時出錯 該軟體包正處於非常不穩定的狀態 您最好在配置它之前,先重新安裝它 正在設定 ssh 1 7.2p2 4ubuntu1 在處理時有錯誤發生 gir1.2 unity 5.0 amd64 e sub proc...

編譯核心出現的問題解決辦法

1.cc1 error code model kernel does not support pic mode cc1 error code model kernel does not support pic mode 修改li li vir linux 3.14 linux 3.14 vim ma...