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

.htaccess設定網站預設首頁次序

.htaccess設定網站預...

一般php空間預設設定是index.php為首頁。 所以如果網站用index.php做首頁,就不需要...

PHP查詢陣列中是否存在特定字串in_array() 函數

PHP查詢陣列中是否存在特定...

使用函數inarray() ,適用版本(PHP , PHP 5, PHP , PHP ) 使用方式:...

使用PHP取得指定月份最後一天的日期

使用PHP取得指定月份最後一...

使用PHP要如何抓某個月份的最後一天 例如抓本月份的話可以使用下列範例: date(&#;Ymt&#...

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