[英]How to store custom entity properties in a relational database
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?
我应该在一个表中使用外键指向每个表和键/值列,还是有更好的方法呢?
You are speaking of "Entity Attribute Value" tables. 您说的是“实体属性值”表。
Entity Tables: 实体表:
Ent1 (Eid, name, desc, etc...)
Ent2 (Eid, name, desc, etc...)
Attribute (EAV) Tables: 属性(EAV)表:
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. 您可以将两个EAV表合并为一个,然后创建一个MUCK(大型统一代码密钥)表。 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.
几乎每个人都曾经尝试过它,因为乍一看似乎很容易,但它却变成了怪物。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.