Pat Hartman (MVP) said:
You need a table to hold
employee data and you need a table to hold time reporting data. The
employee table is a self referencing table and so can link to other records
in the same table. This is the preferred structure since supervisors and
managers are also employees and you can't arbitrarialy limit the hierarchial
structure to three levels since there could easily be more.
tblEmployee:
EmployeeID (autonumber primary key)
FirstName
LastName
ReportsTo (foreign key to EmployeeID in tblEmployee)
The ReportsTo field allows each employee to report to a single individual in
the management chain.
Preferred by whom? "Committing spreadsheet" (thanks JohnV) is also very
common, therefore must be a *preferred*by a significant number of people
(arguably newbies with the wrong mental model) but that doesn't make it 'best
practice'. The author of the book 'Trees and Hierarchies in SQL for
Smarties', Joe Celko, prefers the nest sets model (see
http://www.dbazine.com/ofinterest/oi-articles/celko24).
This structure as posted is denormalized e.g. redundancy in your 'reports
to' column. Remember that a table either models entities (e.g. Employees) or
a relationship (e.g. OrgChart) but not both. The org chart exists independent
of the people who currently hold the positions. Is 'parking space number' an
attribute of an automobile? Of course not and the same applies to the org
chart.
If this is not your structure you will need to use
two tables to create this relationship.
OK you can normalize your earlier structure by using two tables instead of
one but you'd need to add constraints to remove INSERT/DELETE anomalies i.e.
changes that cause cycles and orphaned trees. Then there are the problems of
querying of the adjacency list model e.g. Jet SQL isn't good a recursion so
you'd need as many self joins as there are potential levels in the
hierarchy...
Jamie.
--