views:

156

answers:

2

On MS SQL Server 2005, I have a table that I want to replace. Many other tables have a Foreign Key reference to this table. Is there a script that I can run to simply roll over all these references from the old table to the new table?

Or am I going to have to go through and specifically drop each of these foreign keys, and write a new key for each one?

+1  A: 

You are safer dropping and recreating them for the new table.

Otávio Décio
Ended up doing this. Pain in the whumpus.
Jeffrey
I feel ya. I had a similar answer some days ago for a developer that wanted to go vb5->c#; sometimes you just have to do it and get it behind you.
Otávio Décio
+1  A: 

Or, can you re-use the same Primary Keys for the new table that were in the Old table you are replacing? Then you don't have to update the FKs at all.

If the Primary Key is auto-incrementing "Identity" column, you can use "Set Identity_Insert On", to allow you to insert new records into the new table's identity column with an explicit value (the pk from the old table). Run Set Identity_Insert Off when you're done and you're off and running.

Charles Bretana
This sounds really promising. I'm-a going to go play around with this.
Jeffrey