如何重新编号主索引 [英] How to renumber primary index

查看:32
本文介绍了如何重新编号主索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 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);

这篇关于如何重新编号主索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆