I have a table regionkey:
areaid -- primary key, int
region -- char(4)
locale -- char(4)
The rest of the database has a foreign key for areaid. This table has an index on (region, locale) with a unique constraint.
The problem is that I have two entries:
101 MICH DETR
102 ILLI CHIC
And I need to change the fields (region, locale) between them, so that I finish:
101 ILLI CHIC
102 MICH DETR
The naive approach will not work, as it violates the unique index for the region and locale:
update regionkey
set region='ILLI', locale='CHIC' where areaid = 101;
update regionkey
set region='MICH', locale='DETR' where areaid = 102;
How can i do this? Is there an atomic way to do a swap? Suggestions?
source
share