How to update the primary key of a table that is listed as a foreign key in another table?

Assume that a

Table "Person" having 
    "SSN",
    "Name",
    "Address"

and further

Table "Contacts" having
    "Contact_ID",
    "Contact_Type",
    "SSN" (primary key of Person)

similarly

Table "Records" having
    "Record_ID",
    "Record_Type",
    "SSN" (primary key of Person)

Now I want to change or update the SSN in a personal table, which changes accordingly in the other 2 tables.

  • If someone can help me with a trigger for this
  • Or how to pass foreign key constraints to tables
+3
source share
5 answers

Just add UPDATE CASCADE to the foreign key constraint.

+8
source

, . , SSN , SSN . , ON UPDATE CASCADE .

+5

, , , , .

Person, FK . a ON UPDATE CASCADE . , , 300 (FK) , , . Person, ( - , ), Msg 8621, Level 17, State 2, Line 1 The query processor ran out of stack space during query optimization. Please simplify the query.. a ON UPDATE CASCADE , FK .

, SSN a PK. - . , - GET POST SSN ! SSN , , . ..

+4

, SSN Person, ( , ):

  • SSN, .
  • , .
  • .

, , . , ( SSN ), .

+1

. , . .

, . SSN , . , , , . , , , . , , - ssns ( BTW). - .

An SSN is also a bad candidate because it changes (people change them when, for example, they become victims of identity theft.) In addition, an integer PC will have better performance than a nine-digit PC.

+1
source

Source: https://habr.com/ru/post/1745103/