简体   繁体   中英

Single Relation M:N for unknow element number

Currently I have an article with various M:N relations with other elements, the problem is that these elements can and will grow up and not want to have that amount of tables in my database.

在此处输入图片说明

which is the right way to build a single relationship M: N for an unknown number of elements

Which is the right way to build a single relationship M: N for an unknown number of elements

There is nothing particularly wrong with having separate junction table for each of the M:N relationships.

That being said, you can handle these relationships in a more generic way, and at the same time lower the number of tables by using inheritance 1 :

在此处输入图片说明

For more information about the concept of inheritance, search for "Subtype Relationships" in ERwin Methods Guide . For some hints at how the inheritance can be implemented in a relational database, take a look at:


1 Aka. category, subclassing, subtyping, generalization hierarchy...

If all elements would have same attributes You could keep them all in one table with extra column(enum best) to distinguish between them.

But looking at image You provided they probably don't have same attributes so it would be difficult and inefficient to somehow force them to be in one or just few tables.

There is no limit on number of tables You may create and I have no idea why should You avoid creating a new table for each relation as it should be.

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