Home  >  Q&A  >  body text

How does MySQL implement nesting of another table within a table?

1. I am a database novice... If I want to realize the A column in database table 1, how to implement the BCD column in nested table 2? Use foreign keys?
2. If I use foreign keys, I always get errors when creating and saving them:

incorrect foreign key definition for 'xxx':key reference and table reference dont match

What's going on with this problem? How to solve it?

为情所困为情所困2710 days ago631

reply all(1)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-18 10:52:13

    The use of foreign keys is not recommended. Foreign keys will cause coupling between tables and may cause deadlocks. And these errors are not easy to find during the programming process.

    Suppose you now want to combine table A and table B. Then you add a new column in table A to save the id value in table B.

    • Saving process: Save table B first, then return the id value and save it into table A.

    • Retrieval process: First retrieve table A, and then retrieve the corresponding table B data based on the id of table A.

    reply
    0
  • Cancelreply