Need to update a table PK with a value from an adjacent column

Hi,

Altering my db to use a different table structure. (supertype subtype table).

To make all FKs that are relative to the PK of one table, use the new PK, I need to update it in the old table. The col with the new values is besode the col with the old ones - in the same table.

will this query copy them the correct way around? I’d hate to update the new values with the old ones. :rolleyes:


UPDATE table_name
set id = new_id

bazz

This query will take, for every row in table_name, and assign the id column the value in the new_id column.

Be careful of collisions.

I should add that the db table is not yet being used by any aps, so it is not live - if other updates or queries being made, were what you were referring to when you mentioned collisions.

bazz

Thank you for your reply.

So if I have these values

|1|360|
|2|361|
|3|362|
|4|363|
|5|364|

will each of the left column (1-5) be updated with the value in its corresponding right column (360 -365) so 1 becomes 360, 2 becomes 361, 3 becomes 362 etc?

What do you mean by collisions? each left col is unique as is each right col. and the max number in left col is 175 and the min number in the right col is 360

bazz

took the plunge and it went swimmingly :slight_smile: