Reputation: 3511
I have a table with a primary key that I would like to add another column to. The problem is, when I add this, Sql Server drops all foreign key references to that table.
Is there any way to fix this? (or maybe even a tool that refactors this)?
Upvotes: 4
Views: 171
Reputation: 4609
There is no way to get around it. Foreign keys will have to be redefined. If you are for example, adding a column to your PK, all the existing FK's will need to be redefined to reference the new set of columns that make up the PK. This means you'll have to add columns to the child tables.
I'm not sure if there are any tools that automate this process.
Upvotes: 0
Reputation: 65157
There's nothing to "fix" - you are changing the PK, so the FKs need to be dropped.
What do you think should happen if you add a field to the PK - all FK references get the field added as well? What if that extra field doesn't exist in your other tables? They have to be dropped and then recreated to make sure they are even valid references.
Upvotes: 5