T
TC
duplication problems).I am a beginner at this (but am determined to break away from my one-table
You've made a very good attempt, and your comments do not sound like a
beginner's!
I'm doing from top to bottom:I can't figure out what I'm doing wrong, though. Let me describe what
I've taken the liberty of rearranging and rewording parts of your original
post, in order to put my comments in the right places.
district, and has an instructor & a principle.There are "districts":
tblDISTRICTS
fldDistrictID (PK)
fldDistrictName
Fine.
Each district contains many "residents":
tblRESIDENTS
fldResidentID (PK)
fldResidentName
fldDistrictID (FK to tblDistricts)
fldClassID (FK to tblClasses)
Fine.
There are various "classes", each of which is sponsored by a single
residents can be assigned to classes that belong to a different districttblCLASSES
fldClassID (PK)
fldClassName
fldDistrictID (FK to tblDistricts) <- sponsoring district.
fldInstructorID (FK to tblEmployees)
fldPrincipalID (FK to tblEmployees)
Fine.
The Instructors and Principals are both "employees":
tblEMPLOYEES
fldEmployeeID (PK)
fldEmployeeName
Fine.
All residents go to classes. This is complicated by the fact that the
from the one they live in. From what I have read, I think I need some type
of intermediate table(s) between the primary "tblDISTRICTS" table and the
"tblRESIDENTS" and "tblCLASSES". (snip rest).
If a resident can go to many classes, and a class can have many residents,
this a classic many-to-many relationship between those classes & residents.
You resolve this by creating a junction table with a so-called "composite"
(multi-field) primary key. The composite primary key comprises, the primary
keys of the tables wth the M:M relationship. So:
tblCLASS_RESIDENT
fldClassID ( composite )
fldResidentID ( primary key )
other (non-key) attributes for *that resident* in *that class* - for
example, date enrolled.
To add a resident to a class, just create the appropriate new record in that
new table. Note that it is irrelevent what district the resident lives in
(but this could, if necessary, be obtained by looking-up that resident in
the RESIDENTS table), and also, it is irrelevent what district sponsors that
class (but that could, if necessary, be obtained by looking-up that class in
the CLASSES table).
So you were just about 99% there!
HTH,
TC