简体   繁体   中英

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. 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. users , items , work . The notes.tag_id is the ID of the row of the object.

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. Then, you don't need the tag field and tag_id can be a true foreign key.

In an ER diagram, I would make the NOTE_* entities to be a disjoint is-a of a NOTE entity. However, I would not "materialize" it as a table in the database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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