PHPMyadmin 中的行递减/递增
我的数据库中有一个表 newvehicles ,其中包含以下字段:
id (AUTO_INCREMENT)
make
model
doors
bodystyle
price
这是一个示例:
1 Volkswagen Golf 2.0 GTI 3 Hatchback $39,490
2 Ford Mondeo 2.3 Zetec 4 Sedan $54,450
3 BMW 3-Series 318i 4 Sedan $62,667
4 Renault Clio 1.2 Base 3 Hatchback $22,686
5 Volvo S60 3.2T SE 4 Sedan $49,460
6 BMW 5-Series 540i 4 Sedan $89,990
如果我删除了第 4 行,它将包含第 1 行, 2、3、5 和 6,为了重置增量,我使用以下代码:
UPDATE automobiles SET id=id-1 WHERE id > 3
但是,有什么方法可以自动让 phpMyAdmin 重置增量值对于 id 字段(因为它有一个自动增量),我真的不想每次都继续使用上面的代码。
顺便说一句,不确定这是否相关,但数据库存储为 InnoDB,以防万一我必须为可能链接到它的其他数据库做外键。
我对此很陌生,所以非常感谢您的帮助!
I have a table in my database, newvehicles which has the following fields:
id (AUTO_INCREMENT)
make
model
doors
bodystyle
price
and this is an example:
1 Volkswagen Golf 2.0 GTI 3 Hatchback $39,490
2 Ford Mondeo 2.3 Zetec 4 Sedan $54,450
3 BMW 3-Series 318i 4 Sedan $62,667
4 Renault Clio 1.2 Base 3 Hatchback $22,686
5 Volvo S60 3.2T SE 4 Sedan $49,460
6 BMW 5-Series 540i 4 Sedan $89,990
If I deleted, say, row 4, it would have rows 1, 2, 3, 5 and 6, and in order to reset the increment I use this code:
UPDATE automobiles SET id=id-1 WHERE id > 3
However, is there any way I can automatically get phpMyAdmin to reset the increment values for the id field (since it has an auto increment in) and I don't really want to keep using the above code every time.
By the way, not sure if this relevant, but the database is stored as InnoDB, just in case I have to do foreign keys for other databases that may link to it.
I'm fairly new to this, so would appreciate the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
自动递增值用作唯一标识符。因此,稍后如果您将该密钥保存在其他地方,您将始终提取该特定记录。
如果您想要一个始终连续的数字,我建议您在显示它们时使用计数器。我认为从长远来看这会节省工作量。
The auto-increment value is used as a unique identifier. So later if you save that key elsewhere you will always pull that particular record.
If you want a number that is always sequential, I would suggest using a counter when you display them. I think that would save work in the long run.