如何在关系数据库中存储自定义实体属性 [英] How to store custom entity properties in a relational database

查看:89
本文介绍了如何在关系数据库中存储自定义实体属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为正在开发的应用程序设计数据库。

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.

每个实体可以有0到多个属性,我想知道什么是以关系方式构建这样的数据的最好方法。我应该有一个表有外键的每个表和键/值列,还是有一些更好的方法吗?

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?

推荐答案

实体表:

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

属性(EAV)表:

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

两个EAV表合并为一个,并创建MUCK(大规模统一代码密钥)表。但不要这样做,因为它有一些真正的缺点,从长远来看。几乎每个人都尝试了一下,因为它看起来很容易,但它变成一个怪物。

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.

关系数据库中的键值对

这篇关于如何在关系数据库中存储自定义实体属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆