Dear Potter:
You are correct that the table on the "many" side of a one-to-many
relationship does not require that all the columns in its primary key (or
other unique key) be used in the relationship. Indeed, it is not always the
case that the column(s) in the "many" table are indexed at all.
However, all the columns of the table on the "one" side of the relationship
must together be unique (when taken together), so a unique index (including
a primary key) is required. It is required not only for uniqueness, but
because it gives good performance to have this index. It is used whenever
you JOIN to it using this relationship.
"Why not leave all the data in one table?" Well, where shall I begin:
- The information in the set of columns forming what is properly the table
on the "one" side of the relationship will be repeated many times. If you
should ever need to change anything, such as just correcting a spelling, you
would have to enter that correction many times. Perhaps you expect to just
make changes in the spreadsheet and then import it, in which case this is
likely what you mean to do anyway. But it doesn't have to be that way.
- It is not uncommon to have a hierarchy of tables in one-to-many
relationship. Consider the organization of a country. It has many states.
Each state has many counties. Each county has many townships. Each
township consisits of many properties. Each property may have many
residents. Each resident has several bank accounts. Each bank account has
many deposits and withdrawals. Putting all that into a spreadsheet would
result in repeating state, county, township, property, resident, and bank
account just to show a list of deposits and withdrawals. It is proper to
have a key that does this, but do you need to repeat all the other
information about the state (state capitol city name, governor's name, etc.)
many millions of times in order to show every deposit or withdrawal made by
every resident? I don't think so.
Databases are organized, very highly organized, and according to a science
(or is it a mathematics?) This has been developed and tested over much of
my lifetime, and there are reasons for why it is done the way it is done.
It would take a very good chapter in a book to even get started to explain
this. You can buy the book and read it, or you can take my word for it, or
you can suffer the consequences of doing it poorly. If you stay with it,
you'll eventually see what I have been trying to explain. I can only
recommend strongly that you learn this by research before you learn it the
hard way.
Tom Ellison