简体   繁体   English

正确的数据库设计:一个表到多个对象

[英]Proper Database Design: One table to Multiple Objects

Forgive me. 原谅我。 I believe it is a wrong title. 我相信这是一个错误的标题。 but here goes. 但是这里。

Let's put an instance that we have 3 Objects. 让我们举一个实例,我们有3个对象。 USERS , ITEMS , and WORK . 用户项目工作 These 3 objects may contain multiple Notes 这三个对象可能包含多个注释

So I formulated a database design which I tried and it works but I know it's not efficient by performance and I think it's improper. 因此,我制定了一个数据库设计并尝试了它,但是它可以起作用,但是我知道从性能上来看它是无效的,并且我认为这是不合适的。

在此处输入图片说明

As you can see in notes table, notes.tag is the string identifier of the tagged table. 您可以在notes表中看到, notes.tag是带标签的表的字符串标识符。 users , items , work . usersitemswork The notes.tag_id is the ID of the row of the object. notes.tag_id是对象行的ID。

Below is the Notes Table with its sample Value 以下是注释表及其示例值

+----+-------+--------+-----------------------------+--+
| ID | TAG   | TAG_ID | MESSAGE                     |  |
+----+-------+--------+-----------------------------+--+
| 1  | items | 1      | Lorem Ipsum                 |  |
+----+-------+--------+-----------------------------+--+
| 2  | items | 1      | Dolor sit Amet              |  |
+----+-------+--------+-----------------------------+--+
| 3  | users | 1      | consectetur adipiscing elit |  |
+----+-------+--------+-----------------------------+--+

For me, this is quite efficient(and lazy) but I don't really know if this is the proper. 对我来说,这是非常有效的(而且很懒),但是我真的不知道这是否合适。 Do you have any proper suggestions? 您有什么适当的建议吗?

I would make a separate NOTE_USERS, NOTE_ITEM, NOTE_WORK table. 我将创建一个单独的NOTE_USERS,NOTE_ITEM和NOTE_WORK表。 Then, you don't need the tag field and tag_id can be a true foreign key. 然后,您不需要tag字段,并且tag_id可以是真正的外键。

In an ER diagram, I would make the NOTE_* entities to be a disjoint is-a of a NOTE entity. 在ER图中,我将NOTE_ *实体设为NOTE实体的不相交is-a However, I would not "materialize" it as a table in the database. 但是,我不会将其“实现”为数据库中的表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM