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

使用PHP取得目前網址方式

使用PHP取得目前網址方式

pexelsphoto55 使用PHP取得網址相關的方式有下列幾種: $SERVER["R...

使用CSS 讓ul li 橫向水平

使用CSS 讓ul li 橫...

好吧,其實這個css常在用,但我每次都沒特別紀錄,然後每次又忘記然後又要Google。 其實主要就是...

修改php.ini更改允許上傳檔案的大小

修改php.ini更改允許上...

使用vi或vim開啟php.ini #vim /etc/php/apache/php.ini 找到以...

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