I have a master table with field UserName. All other tables in the system (that deal with order information, etc.) reference this field as a foreign key. If I delete that user I'll delete their records, except for the fact that I have ON DELETE RESTRICT in place. Life is good.
Now, suppose I have JSmith01 and JSmith02 in the system and want to merge his record (it's a duplicate). I'm thinking I can:
- suspend the UNIQUE key constraint in the master table for that field UserName.
- UPDATE mastertable SET UserName='JSmith01' WHERE UserName='JSmith02'
- This would cascade the new UserName value to all of JSmith02's orders
- Get the best of JSmith02's information (if present), update JSmith01's to reflect, then delete JSmith02
- Now, reactivate the UNIQUE key constraint on the field.
Any thoughts on this? Main area I'm interested in knowing about is suspending a reference or overriding it temporarily.
thanks,
Sam