Second Normal Form
- Create separate tables for sets of values that apply to multiple records.
- Relate these tables with a foreign key.
We break the url values into a separate table so we can add more in the future without having to duplicate
data. We’ll also want to use our primary key value to relate these fields:
data. We’ll also want to use our primary key value to relate these fields:
users | |||
userId | name | company | company_address |
1 | Joe | ABC | 1 Work Lane |
2 | Jill | XYZ | 1 Job Street |
urls | ||
urlId | relUserId | url |
1 | 1 | abc.com |
2 | 1 | xyz.com |
3 | 2 | abc.com |
4 | 2 | xyz.com |
Ok, we’ve created separate tables and the primary key in the users table, userId, is now related to the foreign key in
the urls table, relUserId. We’re in much better shape. But what happens when we want to add another employee of
company ABC? Or 200 employees? Now we’ve got company names and addresses duplicating themselves all
over the place, a situation just rife for introducing errors into our data. So we’ll want to look at applying the Third Normal Form:
the urls table, relUserId. We’re in much better shape. But what happens when we want to add another employee of
company ABC? Or 200 employees? Now we’ve got company names and addresses duplicating themselves all
over the place, a situation just rife for introducing errors into our data. So we’ll want to look at applying the Third Normal Form: