If I have two tables tableinfo and tablenamelist and a foreign key like so:
Alter tableinfo add foreign key (name) references tablenamelist(name) on update cascade;
In which situations will the records be modified?
My understanding is that if I change ‘bob’ to ‘Bobby’ in tablenamelist it will update all instances of ‘bob’ to ‘Bobby’ in tableinfo.
What happens though if I change a name in the tableinfo table? If I change a record from ‘bob’ to ‘tim’ will it change records in tableinfo? Or will it just reassign that record to the new name?
Your first assumption is correct, if you change the name in
tablenamelist, it will change in tabletableinfo.Your second assumption is incorrect, you will receive a foreign key violation if you try to change the name in table
tableinfoto something that does not exist in tabletablenamelist.The foreign key is a constraint that enforces the existance of the key in the foreign table.
From Foreign key
Also from 14.3.5.4. FOREIGN KEY Constraints