Since the purpose of the foreign key is to identify a particular row of the referenced table, it is generally required that the foreign key is equal to the candidate key in some row of the primary table, or else have no value (the NULL value.
Because violations of these constraints can be the source of many database problems, most database management systems provide mechanisms to ensure that every non-null foreign key corresponds to a row of the referenced table.
I have a categories table, which one of the fields serves as the foreign key for a sub-categories table.
One field that serves as part of the primary key for each table is the language id. Basically, wherever the language id = x in both tables, I need to set it to y.
I have three tables: categories, languages and categories_languages.Another table called Employee Details has a foreign key which references employee_id in order to uniquely identify the relationship between both the tables.The table containing the foreign key is called the child table, and the table containing the candidate key is called the referenced or parent table.It is possible to implement other semantics using triggers.Additionally, My SQL requires that the referenced columns be indexed for performance reasons.As of 5.6.7, the server prohibits changes to foreign key columns with the potential to cause loss of referential integrity. When you drop a table, any constraints that were defined in the statement used to create that table are also dropped.