Skip to content
Advertisement

Update column of a table with new foreign key of associated table

Let’s say I have a Persons and Books table that were associated.

Currently persons.usercode serves as the primary key and hence the foreign key on associated tables. I would like to change the primary key of the persons table to persons.uid. So now I want the books table to look like

Dropping and adding the new primary key constraint shouldn’t be a problem. However, how do I go about updating the entire books.owner column with the new primary key if I have over 10,000 rows in the books table

Advertisement

Answer

You need to drop/disable the current foreign key & re-add it. You may also need to find out the name of that primary/foreign key constraint before dropping.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement