title: updating primary key of master and child tables for large tables
body: <p>I have a fairly huge database with a master table with a single column GUID (custom GUID like algorithm) as primary key and 8 child tables that have foreign key relationships with this GUID column. All the tables have approximately 3-8 million records. None of these tables have any BLOB/CLOB/TEXT or any other fancy data types just normal numbers, varchars, dates, and timestamps (about 15-45 columns in each table). No partitions or other indexes other than the primary and foreign keys.</p>
  
  <p>Now, the custom GUID algorithm has changed and though there are no collisions I would like to migrate all the old data to use GUIDs generated using the new algorithm. No other columns need to be changed. Number one priority is data integrity and performance is secondary.</p>
  
  <p>Some of the possible solutions that I could think of were (as you will probably notice they all revolve around one idea only)</p>
  
  <ol>
  <li>add new column ngu_id and populate with new gu_id; disable constraints; update child tables with ngu_id as gu_id; renaname ngu_id->gu_id; re-enable constraints</li>
  <li>read one master record and its dependent child records from child tables; insert into the same table with new gu_id; remove all records with old gu_ids</li>
  <li>drop constraints; add a trigger to the master table such that all the child tables are updated; start updating old gu_id's with new new gu_ids; re-enable constraints</li>
  <li>add a trigger to the master table such that all the child tables are updated; start updating old gu_id's with new new gu_ids</li>
  <li>create new column ngu_ids on all master and child tables; create foreign key constraints on ngu_id columns; add update trigger to the master table to cascade values to child tables; insert new gu_id values into ngu_id column; remove old foreign key constraints based on gu_id; remove gu_id column and rename ngu_id to gu_id; recreate constraints if necessary;</li>
  <li>use <code>on update cascade</code> if available?</li>
  </ol>
  
  <p>My questions are:</p>
  
  <ol>
  <li>Is there a better way? (Can't burrow my head in the sand, gotta do this)</li>
  <li>What is the most suitable way to do this? (I've to do this in Oracle, SQL server and mysql4 so, vendor-specific hacks are welcome)</li>
  <li>What are the typical points of failure for such an exercise and how to minimize them?</li>
  </ol>
  
  <p>If you are with me so far, thank you and hope you can help :)</p>