How can I set up a database schema where there are two concurrent many-many relationships?

蹲街弑〆低调 提交于 2019-12-12 04:44:51

问题


I need a table to hold downtime, basically a downtime event contains the following info:
EVENT_ID, START_TIME, END_TIME, SERVICES, CAUSES

The main issue is that I don't know how to set this up because I don't want to end up with a mess like this:

ID  |  EVENT_ID  |  START_TIME  |  END_TIME  | SERVICES  |  CAUSES
01          455       12:00          12:30      FINANCE     NETWORK
02          455       12:00          12:30      ADVANCE     NETWORK
...
13          455       12:00          12:30      REFRESH     DATABASE

Basically...for a single outage, I would have many many entries in the table, since if there are multiple services/causes, the table would in effect hold all combinations.

Is there a more efficient way of organizing this?


回答1:


yes - normalize a little:

EVENT
------
event_id
start_tm
end_tm
description

EVENT_SERVICE
-------------
event_id
service_id
employee_id 
start_tm
end_tm
(other info as needed)

SERVICE
---------
service_id
description

CAUSE
-------
cause_id
description

EVENT_CAUSE
-----------
event_id
cause_id

edited to reflect ypercubes comment with a separate SERVICE table



来源:https://stackoverflow.com/questions/9625213/how-can-i-set-up-a-database-schema-where-there-are-two-concurrent-many-many-rela

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