Database design: one table versus three tables

I have the following situation, and I would like to know your opinion and feedback. My applications have a company. Each company has many departments, which, in turn, have many users. I have a calendar at all levels. Thus, there is a central calendar for the company, a separate calendar for each department and a separate calendar for each user. The idea is that when a user is interested in an event in the company, he / she can add it to his calendar. Now I need to have one or more tables for events. I thought it was worth

  • I should have one table, in which there will be a field for the unique identification of each entity (company, department, user), and depending on who requests, I can accordingly receive the results
  • I should have some tables. One table for the company, One table for the departments, One table for the users.

So this is more like a single table versus three tables.

+3
source share
3 answers

Look at the requirements for applications - if the events for different levels are essentially the same (have the same data requirements, behavior), you probably should just use the same table. If they are different, use different tables.

+1
source

, , , . , , , ?

, :

CALENDAR_ID

EVENT_ID

"EVENT_TO_CALENDAR" ( "-":

CALENDAR_ID
EVENT_ID

, " ", EVENT_TO_CALENDAR EVENT_ID, CALENDAR_ID. ( ).

+1

I think I will argue about three tables. First of all, if you select one table, it will receive three zero foreign keys. This means that you cannot guarantee consistency only from the database model, but you must guarantee it somewhere in your business logic. Secondly, over time, you will most likely find out that the company’s calendar is slightly different from the calendar of an employee or department. The latter may require, for example, an additional column. You simply cannot predict this.

0
source

Source: https://habr.com/ru/post/1753245/


All Articles