Hmmm. I think I'm lost. My table will have a key that represents the
persons ID, in my case it would be salerjo01. This will be what ties
this table to that person. Can I repeat this key multiple times in the
Education table?
The "person ID" is only a primary key for the "person record"... You
can use it to link to the person in as many tables/records as needed.
Each of those other tables, though, should have something that is a
primary key for them.
Some text books even recommend that the primary key be totally
useless outside the database (so, no hashing of last name and date of
birth, etc. -- it should just be a database assigned number, used only
within the database, but not for external reports).
Recommend you look for some textbook (or do a Google search for a
tutorial) that discusses: Codd Normal Forms, Relational Database Design,
Normalization.
Let's start with a very unnormalized record (I won't bother with
data types, and some "fields" actually have more subfields inside --
I'll cover those in later phases):
StudentRecord(sID, sName, sDOB, sSchool_1, sSchool_2, sSchool_3)
(where sSchool_x is really a collection of
[name, start, end, degree, major] )
" 123, Great Pumpkin, 1955, (hard knocks, 1956, 1960, BS, Terror),
(Petaluma Agricultural, 1960, 1962, MS, Gourds), (empty) "
This is a bad design... If a student doesn't have any school data,
you are storing empty fields. OTOH, if a student has more than three
schools, you are unable to store all of them. First refactoring to solve
this...
StudentRecord(pKey, sID, sName, sDOB, sSchool)
"1, 123, Great Pumpkin, 1955, (hard knocks, 1956, 1960, BS, Terror)"
"2, 123, Great Pumpkin, 1955, (Petaluma Agricultural, 1960, 1962, MS,
Gourds) "
Better, we can just add another record for each school. Bad: we are
repeating the student ID, student name, DoB for each school (note the
new primary key) -- it is possible to get conflicting data (what happens
if someone updates the second record and changes the DoB to 1559?)
We must split the table!
StudentRecord(sID, sName, sDOB)
" 123, Great Pumpkin, 1955 "
EducationRecord(eID, sID, eName, eStart, eEnd, eDegree, eMajor)
" 89, 123, hard knocks, 1956, 1960, BS, Terror "
"255, 123, Petaluma Agricultural, 1960, 1962, MS, Gourds "
Note how each education record has its own primary key (eID), AND
has the foreign key identifying the student.
To retrieve the combined data:
select sID, sName, sDOB, eName, eStart, eEnd, eDegree, eMajor from
StudentRecord
left join EducationRecord
on StudentRecord.sID = EducationRecord.sID
order by StudentRecord.sID, eID;
(Note: the "order by" presumes the education records were entered in
chronological order and that the primary key was an "auto-increment"
type, so newer data has higher values... A more formal "order by" would
specify perhaps the eStart date)
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/