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 取得今天日期

JavaScript 取得今...

JavaScript 使用 Date() 來取得時間的資訊。 再使用指令如 getDate()、ge...

要如何修改Plesk空間上傳檔案大小的限制

要如何修改Plesk空間上傳...

Plesk的預設狀況下上傳檔案限制為M。 若要修改上傳限制 首先點選開發工具的PHP設定 innim...

設定Postfix使用SMTP Server當作relay主機

設定Postfix使用SMT...

在/etc/postfix/main.cf 裡修改relayhost 將#relayhost = [...

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