简体   繁体   中英

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

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?

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

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