database design - Modeling Employee-Manager relationship -
each employee in company has unique employee id
a particular number of employees form team, eg employees 1 - 5 form team a
team a, , every other team, has 1 manager. manager employee, own employee id.
what best way of going model relationship?
here couple of suggestions.
groundwork:
assuming employees may member of more 1 team, you'll want separate employees table, separate team table, , table of links between two.
team
- id (pk)
- name
employee
- id (pk)
- name
teamemployees
- id (pk)
- teamid(fk->team.id)
- employeeid (fk->employee.id)
leader:
now groundwork in place, here choices begin - have leader structure:
team table - leaderemployeeid (fk->employee.id)
- advantage - 1 leader per team, simple
- possible disadvantage (depending on requirements) - leader doesn't have employee exists in teamemployees table, additional checks may required
teamemployees table - isleader (bit)
- possible advantage (depending on requirements) - leader has member of team
- possible disadvantage (depending on requirements) - design allows more 1 leader per team, additional constraints needed fix this
Comments
Post a Comment