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

PDO PHP - PDOException - Numeric value out of range: 1264 Out of range value for column user_ip at row 1

PDO PHP - PDOE...

最近遇到一個問題,一個Mysql的錯誤訊息。 我想要紀錄一個IP資訊,我會先用以下方式擷取用戶端使用...

在PHP中如何將NAN轉換為0

在PHP中如何將NAN轉換為...

首先我會得到NAN是因為我有一個計算結果為的值然後我讓他除以,結果就得到了NAN 首先甚麼是NAN?...

php使用PDO獲取結果的方法

php使用PDO獲取結果的方...

fetch() 式例如下: mixed PDOStatement::fetch([int fetch...

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