1.檢視自增列起始值
show create table t10 檢視建表語句
我們看到中的auto_increment=11,代表下一次的自動增長id從11開始,我們可以增加一條資料來驗證一下:
我們看到,auto_increment = 12,所以證明我們的推測是正確的。
2.修改自增列起始值:
alter table t10 auto_increment = 30;
表示修改自增列的起始值為30
我們看到,自增列從id為30開始了
這裡不再舉例,讀者可自行嘗試
mysql:自增步長
基於會話級別:(一次連線有效)
show session variables like 'auto_inc%'; 檢視全域性變數
set session auto_increment_increment=2; 設定會話步長為2(當這次連線斷開,這個步長就失效了)
基於全域性級別:
show global variables like 'auto_inc%'; 檢視全域性變數
set global auto_increment_increment=2; 設定全域性步長
sqlserver:自增步長
基於表級別:
create table t2(
id int not null auto_increment primary key,
name varchar(10)
)engine=innodb auto_increment=4,步長=20 default charset=utf8;
所以,相比下來sqlserver的更加好一 mysql自增ID起始值修改方法
在mysql中很多朋友都認為欄位為auto increment型別自增id值是無法修改,其實這樣理解是錯誤的,下面介紹mysql自增id的起始值修改與設定方法。通常的設定自增字段的方法 建立 時新增 複製 如下 create table table1 id int auto increment pr...
MySQL中自增ID起始值修改方法
在實際測試工作過程中,有時因為生產環境已有歷史資料原因,需要測試環境資料id從某個值開始遞增,此時,我們需要修改資料庫中自增id起始值,下面以mysql為例 表名 users 建表時新增 create table users id int auto increment primary key,666...
MySQL中自增ID起始值修改方法
在實際測試工作過程中,有時因為生產環境已有歷史資料原因,需要測試環境資料id從某個值開始遞增,此時,我們需要修改資料庫中自增id起始值,下面以mysql為例 表名 users 建表時新增 create table users id int auto increment primary key,666...