How should I update ID field values for all records based on previous values?
Question
I need a SQL query that can update ID fields for all records in a table from their previous values to a new value based on that previous value.
For example, if the ID is 1, I want to change it to 9991 - prepending '999' to every ID in the table.
What is the most efficient means of doing this?
Solution
A couple options come to mind. If you have a charish data type:
update table set column=concat('999',column);
If you have an integer type find the max value, let's say it's under 10,000 then
update table set column=9990000+column
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange