简体   繁体   中英

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

1 2 4 5.. .

Instead of

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!

See this question . Assuming your column name is 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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