手机看片精品高清国产日韩,色先锋资源综合网,国产哺乳奶水91在线播放,乱伦小说亚洲色图欧洲电影

幫助中心 >  技術(shù)知識(shí)庫 >  數(shù)據(jù)庫 >  數(shù)據(jù)庫管理 >  mysql數(shù)據(jù)庫自增id重新從1排序的兩種方法

mysql數(shù)據(jù)庫自增id重新從1排序的兩種方法

2016-07-28 08:22:57 6500

mysql默認(rèn)自增ID是從1開始了,但當(dāng)我們?nèi)绻胁迦氡砘蚴褂胐elete刪除id之后ID就會(huì)不會(huì)從1開?了.

使用mysql時(shí),通常表中會(huì)有一個(gè)自增的id字段,但當(dāng)我們想將表中的數(shù)據(jù)清空重新添加數(shù)據(jù)時(shí),希望id重新從1開始計(jì)數(shù),用以下兩種方法均可.

通常的設(shè)置自增字段的方法,創(chuàng)建表格時(shí)添加:

create table table1(id int auto_increment primary key,...)

創(chuàng)建表格后添加:

alter table table1 add id int auto_increment primary key 自增字段,一定要設(shè)置為primary key.

例子,代碼如下:

alter table tablename drop column id;
alter table tablename add id mediumint(8) not null primary key auto_increment first;//phpfensi.com

方法二:alter table tablename auto_increment=0


提交成功!非常感謝您的反饋,我們會(huì)繼續(xù)努力做到更好!

這條文檔是否有幫助解決問題?

非常抱歉未能幫助到您。為了給您提供更好的服務(wù),我們很需要您進(jìn)一步的反饋信息:

在文檔使用中是否遇到以下問題: