I have a record in table with wrong primary key. I want change it to correct value, but this value is used in many other tables.
Is there any simple way to update primary key and foreign key at the same tim?
If the foreign keys are set to cascade changes then the value should change automatically.
Make sure that your foreign key relationships have ON UPDATE CASCADE specified, and the foreign key will automatically update to match the primary key.
From Books Online: http://msdn.microsoft.com/en-us/library/ms174123%28v=SQL.90%29.aspx
ON UPDATE {CASCADE | NO ACTION | SET DEFAULT | SET NULL}
Specifies what action happens to a row in the table that is created when that row has a referential relationship, and the referenced row is updated in the parent table. The default is NO ACTION. See the "Remarks" section later in this topic for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With