How to store custom entity properties in a relational database

女生的网名这么多〃 提交于 2019-12-23 01:16:15

问题


I'm designing a database for a application I'm developing.

I have two tables where the entities can have custom application properties that will define how the data from each entity is used.

Each entity can have zero to many properties and i want to know what the best way is to structure such data in a relational way. Should i have one table with foreign keys to each table and key/value columns or is there some better way to do it?


回答1:


You are speaking of "Entity Attribute Value" tables.

Entity Tables:

Ent1 (Eid, name, desc, etc...)
Ent2 (Eid, name, desc, etc...)

Attribute (EAV) Tables:

Ent1Props (id, Eid, att, value)
Ent2Props (id, Eid, att, value)

You can combine the two EAV tables into one and that creates a MUCK (Massive Unified Code Key) table. But don't do that as it has some real drawbacks in the long run. Nearly everyone has tried it at one point because it seems easy at first, but it becomes a monster.

Key value pairs in relational database



来源:https://stackoverflow.com/questions/29992520/how-to-store-custom-entity-properties-in-a-relational-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!