更新ID列值而无需自动递增

更新ID列值而无需自动递增

本文介绍了更新ID列值而无需自动递增的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前一段时间,我创建了一个表来存储包含用户购买的不同产品的购物清单,但是问题是,每次删除特定行时,都会出现包含标识号的列以及以下标识号消除之后.例如:如果我删除第3行,则标识号显示为

some time ago I created a table to store a shopping list that contains different products that users have purchased, but the problem is that every time I delete a specific row, the column that contains the identification number appears with the following identification number after eliminating it. For example: if I delete row number 3, the identification numbers appear as

1 2 4 5 ...

1 2 4 5.. .

代替

1 2 3 4 ...

1 2 3 4.. .

那么,有人可以帮我写必要的查询来更新标识列吗?

So, can someone help me write the necessary query to update the identification column?

PS:我没有自动递增的那列!

PS: I do not have that column in auto increment!

推荐答案

请参阅此问题.假设您的列名是ID,

See this question. Assuming your column name is ID,

SET @i=0;
UPDATE table_name SET ID=(@i:=@i+1);

这篇关于更新ID列值而无需自动递增的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!