SQL updates table with foreign key

I have a category table in which one of the fields serves as a foreign key for the subcategory table. One field that serves as part of the primary key for each table is the language identifier. I need to update them in both tables. Basically, wherever the language id = x is in both tables, I need to set it to y.

When I try to update in any table, I get an "UPDATE statement that contradicts the REFERENCE .. constraint", which refers to the foreign key constraint.

How to update the language field in both of these tables?

+5
source share
5 answers

If you make the fix 1 time, cancel the restriction, UPDATE and then add the restriction back.

, , , .

+9

, , .

+5

, .

article OdeToCode.

+2
+2

, , .

Admittedly, an ugly alternative is: - Create a row in the parent table based on the row that will be updated but will contain the new foreign key value - Refresh all child rows where the foreign key contains the old value with the new value. - Delete row of unused parent key

This is inconvenient for any number of obvious reasons and may not be suitable for your implementation, but maintains referential integrity in the database.

+2
source

All Articles