I'm working on a database design, and I face a situation where notifications will be sent according to logs in three tables, each log contains different data. NOTIFICATIONS
table should then refer these three tables, and I thought of three possible designs, each seems to have flaws in it:
- Each log table will have a unique incremented id, and
NOTIFICATIONS
table will have three different columns as FK's. The main flaw in this design is that I can't create real FK's since two of the three fields will be NULL for each row, and the query will have to "figure out" what kind of data is actually logged in this row. - The log tables will have one unique incremented id for all of them. Then I can make three OUTER JOINS with these tables when I query
NOTIFCATIONS
, and each row will have exactly one match. This seems at first like a better design, but I will have gaps in each log table and the flaws in option 1 still exist. - Option 1/2 + creating three notifications tables instead of one. This option will require the app to query notifications using UNION ALL.
Which option makes a better practice? Is there another way I didn't think of? Any advice will be appreciated.