I need to shift all the primary keys for table alike
UPDATE TODO SET id = id + 1
but I can’t do it ( Demo from Ahmad Al-Mutawa answer ) descript why. primary key can’t be changed like this.
Also I can’t ALTER the table according that this is sqlite: http://www.sqlite.org/omitted.html
I’m thinking about some hardcoded recursive change for other columnts but without tsql and stored procedures it’s hard for me to get how can I make it?
When you execute your
UPDATEcommand, you will get duplicate IDs temporarily.To avoid this, change the IDs in two steps.
First, pick a number that is larger than the largest ID, and add it to all IDs:
Then, subtract one less from all IDs: