Multiple many to many relations or one option table?

Let’s say I have a database of persons who have some properties. For the sake of this problem let’s say all of these properties relate as N-N.

I can either create two tables for each property (one for different values and one for cross-referencing them to the main object).

Or, I can make the following structure:
enter image description here

Basically having just one huge table of values.

Are there any advantages to this approach? Also, does this approach or pattern have a name that I can look up?

UPDATE:
For example, we make classifier pets with properties cat, dog and fish. So one person may have a cat and a dog (or one pet, or none). And we make a classifier hobby with values skiing, skating, football and TV. So Joe has properties cat, dog, and TV. Then cat and dog are pets and TV is hobby.

The question is, is it worthwhile to put this data using this diagram, or is it a better idea to just create pets, pets_xref, hobby, hobby_xref tables?

3

Unless you fully understand and accept the consequences, doing this is generally not advisable if it can be avoided.

People are often tempted to use this model. In theory you can create any database with just four tables: objects, properties, values, links. While this kind of generic data model is very flexible, it is also very inefficient to query, and any complex queries you have to write against it will be very ugly.

Basically, you are depriving yourself of many of the benefits the RDMS is designed to give you.

Here’s a post which discusses it in more detail: https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::p11_question_id:10678084117056

1

I have to follow Igby, this design you tend to do, is not very suggested. If you ever worked with OR mapper you can understand the problem even further.

Because on your design you would have “multiple entities” (in the mind context) behind “one n:n relationship”.
Rather do the work and build up a new table, relation table and the relation for every “property” (like you call it) of any entity.

You cannot integrate 1:n in your design either. Then you would create new tables for 1:n and none for n:n on the person entity, that is dirty.

1

This answer expands on Igby’s answer, with an example of the kind of query that can be constructed.

There are definitely trade-offs between the two approaches. However, keeping separate tables for different categories can be queried just as easily in SQL.

SELECT UNIQUE pid FROM 
  (SELECT UNIQUE hobbyref.personid AS pid FROM hobby, hobbyref
    WHERE hobbyref.hobbyid = hobby.id AND hobby.type = 'tv')
  UNION
  (SELECT UNIQUE petref.personid AS pid FROM pet, petref
    WHERE petref.petid = pet.id AND pet.type = 'cat'
  )

(Pardon any clumsiness in the SQL. It could probably be expressed more concisely.)

You are basically inventing a database on top of a database. A relational database already have a system to represent properties for entities – it is called tables and columns. By creating your own system on top of this, you are introduction a layer of complexity and at the same time loosing many of the benefits of a relational database. For example this will be much slower than querying a regular database, and you loose all integrity constraints.

That said, they may be particular reasons for choosing such an architecture. For example, if you wants users to be able to dynamically add properties through a UI, it might be easier to achieve. But you should only do this if you really need it and are aware of the drawbacks.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật