简体   繁体   English

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

[英]Update ID column value without auto increment

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 例如:如果我删除行号3,则标识号显示为

1 2 4 5.. . 1 2 4 5。

Instead of 代替

1 2 3 4.. . 1 2 3 4。

So, can someone help me write the necessary query to update the identification column? 那么,有人可以帮我写必要的查询来更新标识列吗?

PS: I do not have that column in auto increment! PS:我没有自动递增的那列!

See this question . 看到这个问题 Assuming your column name is ID, 假设您的列名是ID,

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

As the others suggested, there is probably no need to do this. 正如其他人所建议的那样,可能没有必要这样做。 If you insist, you could try these two steps. 如果您坚持,可以尝试这两个步骤。

ALTER TABLE TableA DROP COLUMN ID

ALTER TABLE TableA ADD ID INT IDENTITY 

Please explain the importance of your change. 请说明您进行更改的重要性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM