mysql 中的 自增長字段如何恢復從1開始計數

2021-08-27 01:13:46 字數 768 閱讀 1290

如果用delete from 表名 來刪除表的全部資料,再往表裡插新資料的話,自增長字段不是從1開始計數的

而用 truncate table 表名來刪除表的全部資料的話,再往表裡插資料的話,自增長欄位就從恢復從1開始計數

mysql資料庫表主鍵自增長的sql語句

1、不控制主鍵的起點

create table emb_t_dictbustype

(emb_c_bustypeid      int not null auto_increment,

emb_c_bustypeenname  varchar(255) not null,

emb_c_bustypezhname  varchar(255) not null,

primary key(emb_c_bustypeid)  

)engine=innodb  default charset=gbk;

2、控制主鍵的起點

create table emb_t_dictbustype

(emb_c_bustypeid      int not null auto_increment,

emb_c_bustypeenname  varchar(255) not null,

emb_c_bustypezhname  varchar(255) not null,

primary key(emb_c_bustypeid)  

)engine=innodb auto_increment=1001 default charset=gbk;

oracle 如何設定主鍵自增(自增長字段)

oracle有點麻煩,需要使用序列和觸發器達到目的。具體步驟如下 一 建立資料表 create table aaa employee id int deptno number,empno number,ename varchar2 16 job varchar2 32 sal float,hired...

mysql 去除列的自增長 mysql自增長列

自增長列必須是索引列,否則無法建立成功表,對myisma和innodb都一樣 localhost testdb root create table test5 id int auto increment,name varchar 10 engine innodb error 1075 42000 l...

往mssql 表的自增長欄位中新增值

使用如下sql語句 set identity insert identitytable on insert identitytable theidentity,thevalue values 3,first row set identity insert identitytable off 上面的一...