Do I have to have a foreign key for data tables in php?

Source: Internet
Author: User
Do I have to have a foreign key in a data table in php? what is this foreign key? is it dispensable and mysterious. I can see that many experts are instructing Cainiao to say they want to create a foreign key, but if you don't want to make sense of it, you will be able to do it again, Ah! Only give fish no fish!


Reply to discussion (solution)

In relational databases, in order to reduce data redundancy, some data is separated from the master table to form
A field that indicates the relationship between a master table and a slave table record. it is called an association key. Broadly speaking, for a table, this key is a foreign key.
The foreign key in the database refers to the association key maintained by the database. The Association key value not available in the master table cannot appear in the slave table.
Obviously, this foreign key is very binding and only used in some demanding scenarios.

Therefore, the conclusion is: foreign keys are not mandatory. blindly setting foreign keys will cause trouble for system operation.

It's too abstract. it's a bit full of concepts.

In relational databases, in order to reduce data redundancy, some data is separated from the master table to form
A field that indicates the relationship between a master table and a slave table record. it is called an association key. Broadly speaking, for a table, this key is a foreign key.
The foreign key in the database refers to the association key maintained by the database. The Association key value not available in the master table cannot appear in the slave table.
Obviously, this foreign key is very binding and only used in some demanding scenarios.

Therefore, the conclusion is: foreign keys are not mandatory. blindly setting foreign keys will cause trouble for system operation.


What is the automatic generation of foreign keys in data design model software such as MySQL Workbench? As mentioned above, foreign keys are so important that they should be manually specified. Why can they be generated at will? Too contradictory

In actual development, external check is not recommended. foreign keys are used only when the system data is sensitive, such as the payment system. if a foreign key is set in Workbench, an SQL statement is generated, however, we recommend that you remove the foreign key when generating an SQL statement to help others understand your database structure.

You do not have to have a foreign key.
If a trigger exists, use it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.