This foreign key is what, it is not dispensable, feel very mysterious appearance. See a lot of experts are pointing rookie said to do a foreign key, but why do not say, on the fairy go also, hey! Only fish are not to be taught!
Reply to discussion (solution)
In the relational database, in order to reduce the redundancy of data, some data is separated from the main table and formed from the table
A field that indicates the relationship between a primary table and a record from a table, called an association key. Broadly speaking, the key is a foreign key to the table.
The foreign key referred to in the database refers to the association key maintained by the database, and the association key value not in the primary table cannot appear from the table.
Obviously the binding force of this foreign bond is very strong, only used in some harsh circumstances
So the conclusion is: foreign key is not necessary, blindly set the foreign key will bring trouble to the operation of the system
It's too abstract, it's a sense of concept.
In the relational database, in order to reduce the redundancy of data, some data is separated from the main table and formed from the table
A field that indicates the relationship between a primary table and a record from a table, called an association key. Broadly speaking, the key is a foreign key to the table.
The foreign key referred to in the database refers to the association key maintained by the database, and the association key value not in the primary table cannot appear from the table.
Obviously the binding force of this foreign bond is very strong, only used in some harsh circumstances
So the conclusion is: foreign key is not necessary, blindly set the foreign key will bring trouble to the operation of the system
What about the automatic generation of foreign keys in the data design model software like MySQL Workbench? Supposedly, foreign keys are so important that they should be specified manually, and why can they be generated casually? It's too contradictory.
Actual development does not recommend the use of external inspection, unless the system data sensitive, such as the payment system will use foreign keys, Workbench if the foreign key set, the generation of SQL will also be taken, but the proposal to generate SQL when the foreign key removed, do foreign keys to help others understand your database structure
There is no need to have foreign keys to see the demand.
Use it if you have a trigger.