Question : Multiple update statement with foreign key constraints

Experts,

I have an collection of update statement that I need to execute.  but for every table the field that I need to update is the PK (user_id)

use users
UPDATE tbluser SET id = 'mlammert' where id = 'mfleer'
UPDATE tbluserTitle SET user_id = 'mlammert' where user_id = 'mfleer'
UPDATE tbluserTeam SET user_id = 'mlammert' where user_id = 'mfleer'

So I assume that I need to drop the constraint every time ? or is there a different way? and if not.. what is the best way to write this in code..

thx

ITBe

Answer : Multiple update statement with foreign key constraints

Hi ITBenelux,

Maintaining a PK while other tables have a FK relationship to it is ... messy.  I would not recommend doing it.

What I suggest you do is:
1. Insert a new row into the PK table with the new PK (done as INSERT ... SELECT ... perhaps);
2. Update the child tables to point to the new row;
3. If required, delete the old row from the PK table.

lwadwell
Random Solutions  
 
programming4us programming4us