Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would go with three-table Kimball star (Date, Employee, Schedule), because sooner or later you will be asked to create (demanding) reports out of this. Who worked most nights? Who worked most weekends? Who never works weekends? Why am I always scheduled Friday afternoon? On which day of a week are certain employees most likely not to show up? Etc, etc...</p> <p>Tables would be:</p> <p><code>TABLE dimDate (KeyDate, FullDate, DayOfWeek, DayNumberInWeek, IsHoliday,... more here)</code><br/> You can pre-fill dimDate table for 10 years, or so -- may need to tweek the "IsHoliday" column from time to time.</p> <p>Employee table also changes (relatively) rarely.<br/> <code>TABLE dimEmployee (KeyEmployee, FirstName, LastName, Age, ... more here)</code><br/></p> <p>Schedule table is where you would fill-in the work schedule, I have also suggested "HoursOfWork" for each shift, this way it is easy to aggregate hours in reports, like: "How many hours did John Doe work last year on holidays?"</p> <p><code>TABLE factSchedule ( <br/>KeySchedule, -- surrogate PK <br/>KeyDate, -- FK to dimDate table <br/>KeyEmployee, -- FK to dimEmployee table <br/>Shift, -- shift number (degenerate dimension) <br/>HoursOfWork, -- number of work hours in that shift <br/>)</code><br/></p> <p>Instead of having the surrogate KeySchedule, you could also combine KeyDate, KeyEmployee and Shift into a composite primary key to make sure you can not schedule same person on the same shift the same day. Check this on the application layer if the surrogate key is used.<br/> When querying, join tables like:</p> <p><code> SELECT SUM(s.HoursOfWork)<br/> FROM factSchedule AS s <br/>JOIN dimDate AS d ON s.KeyDate = d.KeyDate <br/>JOIN dimEmployee AS e ON s.KeyEmployee = e.KeyEmployee <br/>WHERE <br/>e.FirstName='John' AND e.LastName='Doe' <br/>AND d.Year = 2009 AND d.IsHoliday ='Yes';</code></p> <p>If using MySQL it is OK to use MyISAM for storage engine and implement your foreign keys (FK) as "logical only" -- use the application layer to take care of referential integrity.</p> <p>Hope this helps. <br/><br/></p> <p><a href="https://i.stack.imgur.com/YKGjk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YKGjk.png" alt="empschd_model_01"></a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload