问题
Heres my problem.
I have an autoincrement primary key in sql table lets say table look like this
ID | Name|
1 John
2 Jack
3 Bill
4 Joe
Then i delete row 2 Jack
ID | Name|
1 John
3 Bill
4 Joe
And what I want to achieve is to change id column so the table will look like this
ID | Name|
1 John
2 Bill
3 Joe
Is there a way to do it ? thanks in advance
回答1:
I will never do that but you can:
- create a new autoincrement primary key named ID2
- delete ID column
- rename ID2 column as ID
回答2:
Set identity_insert Table off;
Update Table set ID = 3 where ID = 4;
...
Set identity_insert Table on;
Where Table name is Table
来源:https://stackoverflow.com/questions/16691885/renumber-auto-increment-column-in-sql