简体   繁体   中英

different many-to-many relationships in a single table

I'm thinking about merging different many to many relationships in a single table and I would like to know if you think that's smart.

Here are two examples with two separate "relationships" tables:

  1. table: products
  2. table: product_categories
  3. table - relationship table: link_products_product_categories

another example:

  1. table: users
  2. table: user_categories
  3. table - relationships table: link_users_user_categories

Do you think it is smart to create a single table called for example "relationships", which would have fields like this:

  • first_field_table: users
  • second_field_table: user_categories
  • first_field_id: 2
  • second_Field_id: 5

or

  • first_field_table: products
  • second_field_table: product_categories
  • first_field_id: 3
  • second_field_id: 5

That would require some changes in my framework, but it would mean a lot less tables. Do you think that's a good idea to store all these relationships in a single table and identify both tables with fields or is it better to keep them separate and have more tables?

"..but it would mean a lot less tables.."

Many tables is not a bad thing per se. Your solution should have as many tables you need as long as you follow the rules of database normalization.

And to answer your question, no It's not good. Infact It's really bad! All it does is cause huge confusion.

Simple answer no it is not smart.

What is the problem with having lots of tables?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM