Loading...

如何將mysql table auto_increment重設

Temperature: 0 °C

Mark ChangMark Chang
author_tools


如何將mysql table auto_increment重設

資料表裡的資料加加減減,一不小心突然驚覺當初的欄位長度設定的不夠⊙_⊙

當然,你可以選擇再把欄位長度加長。

但事實上,在加加減減的過程中,其實有很多排序數是被浪費了~

例如你新增了資料共有6筆,auto_increment 分別是1、2、3、4、5、6。

今天,你刪掉了一筆資訊,也許是3,那麼,你不用期待4、5、6會自動降下來遞補。

也許你又刪了一筆資訊,也許是6,接下來你又新增了一筆資訊,猜猜會發生什麼事?

答案是,新增的一筆資訊 auto_increment 會從7開始排列。

就這樣無形中我浪費了很多排序數。

所以我得解決這個問題,讓資訊重新開始排列。

參考了Url link

我用了以下方式~

SET @num := 0;
UPDATE my_table_name SET id = @num := (@num+1);
ALTER TABLE my_table_name AUTO_INCREMENT =1;

接下來的結果讓人滿意~
 

https://innstory.com/story-如何將mysql_table_autoincrement重設-1803
Mysql

Prev
 判斷字串是否存在於內容中

Next
PHP_字串字數計算並隱藏 

About the Author

Mark Chang

離不開電腦的宅男

Visitor message

Leave some footprints to prove that you visited me

  • guest

    訪客 2021-02-24 11:21:31 0

    學習

Recommended reading

Author's other related stories

使用javascript獲取ckeditor textarea的textarea值

使用javascript獲取...

一般來說,若我想使用 javascript 來得到 textarea 的值。 可以使用以下方式: 首...

Font Awesome Icon Sizes

Font Awesome I...

pexelsphotoicon5 紀錄一下Font Awesome icon尺寸設定 faxs fa...

PHP輸出到WORD跟EXCEL 簡易做法

PHP輸出到WORD跟EXC...

pexelsphotooffice WORD: $filename="test.doc&q...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format