让mysql在连续范围内重新分配id

发布于 2024-08-24 05:10:05 字数 174 浏览 1 评论 0原文

我在 mysql 中有一个现有的数据库。我的一张表的 id 不连续。我想修改表的 id,使它们从 1 变为 行数

这个特定的表碰巧没有传入引用,因此可以更改 id,而无需修改其他表。

我想这样做的原因是我想用我正在编写的工具处理数据,如果 ids 是连续的,那么很多事情都会更简单。

I have an existing database in mysql. One of my tables has discontinuous ids. I would like to modify the ids of the table so that they go from 1 to num-of-rows.

This particular tables does not happen to have incoming references, so the ids can be changed without modifying other tables.

The reason I want to do that is that I want to process the data with a tool I am writing and if the ids are continuous then many things will be simpler.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无法言说的痛 2024-08-31 05:10:05
SET @r := 0;
UPDATE  mytable
SET     id = (@r := @r + 1)
SET @r := 0;
UPDATE  mytable
SET     id = (@r := @r + 1)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文