Download Growing Better Software

Transcript
69
This may seem a bit confusing at first, so let us take a look at an
example. We will create a simple, one­table telephone book
database. As multiple people can have the same name, we
identify them by a separate key, which we will call person_id.
This is not required for phone numbers, because they are their
own identification. So, our simple phone book looks as follows
(according to principle 1):
Table person
person_id
(primary key)
person_name
phone_number
1
P. Fink
555­5782
2
M. Plow
555­3226
A new requirement just got in: Some people have more than one
phone number, and we must be able to store it. As the field
person_id is a primary key, it can not be duplicated in the
table. We have two options: One is to add another phone
number column (this is a step in the wrong direction, as
discussed in previous chapters), and the other is to separate
phone numbers from people. This will give us the following:
Table person
person_id
(primary key)
person_name
1
P. Fink
2
M. Plow