Mysql – DB Design for Event Dependencies

database-designMySQL

I have a series of events (potentially hundreds) segregated into applications. Each one of these events has a dependency on others (except the first one, of course). I'm looking to map all of these dependencies in a table, but I'm not sure the best way to do so. One event can have multiple predecessors, or multiple successors, or both. There are also cases where A is a prereq for B, B is a prereq for C, but A is also a prereq for D, and C and D are both prereqs for E. (I can't assume that the dependency chain is linear.)

I already have a table with all of the events listed with some other details, and the event names are unique. My first thought was to have a "dependency" table that had an ID (PK) field, 'event' field containing the ID from the events table, and a "dependenton" field that also contained an ID from the events table. Obviously each event could have multiple entries if they are dependent on more than one other event. I believe this follows first normal form, but I'm trying to think if there is another design that would be more efficient or easier to work with.

Thank you.

Best Answer

Sounds like a "many:many" relationship.

See my tips on writing an optimal many:many table.

I assume you have a PRIMARY KEY for the Event table; perhaps the event name? It should be used in the many:many table.