search

Home  >  Q&A  >  body text

Questions about foreign keys to tables

The teacher would like to ask, why not create foreign key links directly in MySQL? It is the relationship between the foreign key that directly links the two tables

cleanclean1674 days ago1012

reply all(1)I'll reply

  • DY。

    DY。2020-05-08 01:28:04

    Generally, it is not recommended to use foreign key constraints in databases. Since it is called a constraint, it will definitely have defects:

    Performance: When inserting data into a sub-table, the main table must be judged.

    Concurrency: If you modify the main table, the sub-table (when there is a lot of related data) may cry.

    Scalability: Not conducive to expansion. For example, if you have a website that grows from small to large, when the number of visits, data When the volume increases, you may split the database into separate tables...it is very troublesome to have foreign keys.

    So: the data in your two tables can be related, just write the comments; instead of You must set foreign keys in the table structure.

    reply
    0
  • Cancelreply