Search code examples
database-designsybasepowerdesigner

how to model this database relationship? (sybase powerdesigner)


I'm doing a conceptual model in Sybase PowerDesigner.
The restriction is following:
One doctor can work in only one office at a time during his working time (shift).

I guess Doctor - Office relationship should be many-many, but what about 
time restriction ("during his working time")?
Should it be a new table SHIFT?

So I guess I should have four tables (DOCTOR, OFFICE, SHIFT and OFFICE SCHEDULE).
OFFICE SCHEDULE should be a table connecting all 3 other entities 
and should have composite primary key (id_doctor, id_office, id_shift)?

Solution

  • The primary key of OFFICE SCHEDULE should be (id_office, id_shift). id_doctor should be in the table, but not part of the primary key. This will enforce the rule that given an office and given a shift there can be at most one doctor in that office.

    Of course, all three of these are foreign keys in addition to the two that form the primary key.