My question is two fold,
- firstly, is it possible to create a foreign key,in mysql, from a referencing table to a column in the referenced table that is not a candidate key ? I tried it using SQLYOG schema designer and it created it strangely. Just want to confirm with others out there, before assuming it is a bug maybe with sqlyog or mysql actually allows it.
example :
table1 columns :
ssn : primary key
name : non-candidate key (names can repeat)
table2 columns
id2 : primary key
name_referencing : foreign key to name in table1 (is this foreign key possible??)
2.If the above case is possible, what happens when ‘on delete cascade’ happens. That is, if there are same values (in various rows) of the referenced column, does the deletion of the child(in referencing) happen only on the deletion of the last value(of the repeated values) in the referenced table ?
So, MySQL actually allows this situation. Weird. Oracle and PostgreSQL will not (both raise errors), and I don’t believe the SQL standard allows it (but haven’t checked, so could be wrong there). Let’s see how it handles it:
So, MySQL deletes the row from the referencing table. At least in 5.1.49.