When modelling a Type/Sub-type (aka Class/Sub-class) relationship the
primary
key of each is the same, in this case PersonID for the tables People,
Students and Teachers. You can of course call the keys of Teachers and
Students TeacherID and StudentID if you prefer, but my own preference is
wherever possible to use the same name for each. The primary keys of the
latter two are also foreign keys referencing the primary key of people;
this
is what creates the one-to-one relationship type. Bear in mind, however,
that the relationship type is nevertheless directional from the Type to
the
Sub-type, so by enforcing referential integrity a row can only be inserted
into a table modelling a sub-type if a referenced row already exits in the
table modelling the (super) type. While the key of People can be an
autonumber, those of Students and Teachers cannot of course.
What characterizes a Type/Sub-Type model is that every sub-type shares the
attributes (and thus columns) of the (super) type, i.e. those which are
common to all such as people's names, but each sub type does not share any
attributes which are specific to other sub-types. An entity (person in
this
case) can of course be an entity of more than one sub-type. My own wife
is a
college lecturer, but she has to my knowledge also simultaneously enrolled
as
a student on at least one course at her own college.
When it comes to other tables which are related to the people, for those
which have a relationship to both students and teachers, an enforced
relationship with teachers should be created, while for those which relate
specifically to teachers or students an enforced relationship with either
Teachers or Students should be created. A CoursesTaught table would thus
be
related to Teachers and Courses, modelling a many-to-many relationship
between Teachers and Courses; a CoursesTaken would thus be related to
Students and Courses, modelling a many-to-many relationship between
Students
and Courses. In passing I'll point out that things do get a little more
complex here as if teacher A teaches course B, and student C takes course
B,
this might not necessarily mean that student C is taught by teacher A as
more
than one teacher might teach that course. There are ways around this by
normalizing to a more advanced level, but I think it would perhaps only
confuse matters to explore that avenue at present. We can always come
back
to it later if necessary.
With this model, attribute values relevant only to a teacher or a student
can
only be entered for a person who is a member of the relevant sub-type, and
data can only be entered in related tables where appropriate to the
sub-type
of which the person is a member, a teacher cannot be enrolled as a student
in
the CoursesTaken table for instance unless, as with my wife, they are also
represented in the Students table, which I think answers your last point
about accidental entry of inappropriate data.
Ken Sheridan
Stafford, England
Lars said:
An additional question. With the subcategory approach (with tblPeople and
tblStudent) should I give the student table it's unique student ID number
and link the specific student child tables to that student ID number? Or
should I link everything to the people ID_number and forget about a
specific
student ID number? I guess the first option would be better since it
prevents users from (accidentally) entering student type of info for a
teacher.
Lars
This makes me assume that I need a central Person table, like you
described.
[quoted text clipped - 57 lines]
have any other child tables that apply to both types, that would
probably
change my recommendation to the subcategory approach.