我有一个简单的 MySQL 表,主索引 (id) 没有一一编号(1、31、35、100 等).我希望它们被编号为 (1, 2, 3, 4).请告诉我怎么做.我还想指出,我知道操作可能带来的后果,但我只是想整理一下桌子.
I have got a simple MySQL table and primary index (id) is not numbered one by one (1, 31, 35, 100 etc.). I want them to be numbered like (1, 2, 3, 4). Please tell me how to do it. I would also like to point that I am aware of possible consequences of the operation, but I just want to tidy up the table.
我同意其他方法也可以,但我只是给出了不同的想法.这将不需要任何临时表创建要求::
I agree other methods will work but I'm just giving a different idea. This will do without any temp table creation requirements::
SET @i=0;
UPDATE table_name SET column_name=(@i:=@i+1);
这篇关于如何重新编号主索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!