如何更正 MySQL 表 ID? [英] How can I correct MySQL table id's?

查看:37
本文介绍了如何更正 MySQL 表 ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为posts"的表,它包含 500 个帖子,但 id 不是序列喜欢:

I have a table called "posts" and it contain 500 posts but the ids are not sequence like:

1
3
9
22
446
....
etc.

那是因为我从表格中删除了一些帖子.

That's because I deleted some of the posts from the table.

那么我该如何重新更正 ID?

So how can I re-correct the ids?

推荐答案

修复它的最简单方法是创建一个快速脚本来循环遍历表并更新 id 列,然后在您的数据库上运行:ALTER TABLE tblAUTO_INCREMENT = 100;

The easiest way to fix it is to create a quick script to loop through the table and update that the id column and then run on your database: ALTER TABLE tbl AUTO_INCREMENT = 100;

这篇关于如何更正 MySQL 表 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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