My instinct should recommend not trying to change the identifier field of the city table. But there is a lot of information. Therefore, this is more a feeling, not a final point of view.
Instead, I would change the values โโin other fields of the city table. For example, change the name of city1 to the name city2 and vice versa.
For instance:
OLD TABLE NEW TABLE id | name | population id | name | population ------------------------- ------------------------- 1 | ABerg | 123456 1 | BBerg | 654321 2 | BBerg | 654321 2 | ABerg | 123456 3 | CBerg | 333333 3 | CBerg | 333333
(the identifier was not affected, but other values โโwere replaced. It is functionally the same as replacing identifiers, but with โsofter touchโ requests that do not require any changes to table restrictions, etc.)
Then in your linked tables you can do ...
UPDATE Customer SET city_uid = CASE WHEN city_uid = 1 THEN 2 ELSE 1 END WHERE city_uid IN (1,2)
But then do you have other tables that reference city_uid ? And if so, is it possible to repeat this update in all of these tables?
source share