Must there be a foreign key to make a data table in PHP?

Source: Internet
Author: User
Do I have to have a foreign key to make a data sheet in PHP
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!
------to solve the idea----------------------
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

------to solve the idea----------------------
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
------to solve the idea----------------------
There is no need to have foreign keys to see the demand.
Use it if you have a trigger.
  • 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.