Home >Database >Mysql Tutorial >How can I renumber a MySQL primary index with non-sequential values in ascending order?
Renumbering Primary Index for Orderly Data
Question:
You have a MySQL table with a primary index whose values are not numbered sequentially. How can you renumber them in order (1, 2, 3, ...)?
Answer:
While other methods are available, here is an alternative approach that does not require creating temporary tables.
Solution:
Execute the following SQL statements:
<code class="sql">SET @i=0; UPDATE table_name SET column_name=(@i:=@i+1);</code>
Explanation:
The above is the detailed content of How can I renumber a MySQL primary index with non-sequential values in ascending order?. For more information, please follow other related articles on the PHP Chinese website!