10
Relational databases and third normal form As always click on speaker notes under view when executing to get more information!

Relational databases and third normal form As always click on speaker notes under view when executing to get more information!

Embed Size (px)

Citation preview

Page 1: Relational databases and third normal form As always click on speaker notes under view when executing to get more information!

Relational databases and third normal form

As always click on speaker notes under view when executing to get

more information!

Page 2: Relational databases and third normal form As always click on speaker notes under view when executing to get more information!

DefinitionsDefinitions

An entity can be thought of as a person, place or thing.

A property of an entity is called an attribute. An attribute of a person is their name. An attribute of a donation is the amount.

An entity relationship is how two entities are associated. It refers to whether both have to exist, whether there can be a one to one relationship, a one to many relationship or a many to many relationship. For example, there is a relationship between a donor and the donations they have made or a student and the courses they have taken.

Functional dependency refers to the relationship between two attributes. If at any time one attribute determines the value of another attribute it can be said that the attribute is functionally dependent on the other attribute. An example is a name which is functionally dependent on a social security number.

A primary key allows you to get one and only one record from a table. All of the other attributes in the table are functionally dependent on the primary key.

A foreign key is an element or attribute on one table that links to the primary key on another table thereby establishing a relationship between the two tables.

A candidate key is a key that could have been used as a primary key. For example, if you use employee identification number as your primary key than social security number is a candidate key because it also uniquely defines.

Page 3: Relational databases and third normal form As always click on speaker notes under view when executing to get more information!

Normal formsNormal forms

First normal form (INF): A relation is in first normal form if there are no groups that repeat. This means that you can not store the information about all the courses that a student has taken on the student table. The information about the courses is a repeating group because there are probably multiple courses.

Second normal form(2NF): First, to be in second normal form you must also be in first normal form. Second you cannot have any non-key attributes that are dependent on only a part of the primary key. For example, in the donation table we said that the primary key would be made up of the donor identification number plus the drive number plus the date of the contribution. Therefore, to be in second normal form no attribute or column in the table can be only dependent on one of these parts. For example, the donor name is dependent on only the donor identification number so it would not be carried in the donation table.

Third normal form (3NF): First, to be in third normal form you must be in second normal form which means you are also in first normal form. Second, you cannot have any determinants on the table that are not candidate keys. For example, if you carry department number on the table you would not carry department name. Department name is determined by department number. You would carry department name on a separate table that you could link to using department number.

Page 4: Relational databases and third normal form As always click on speaker notes under view when executing to get more information!

Donor systemDonor system

In the donation relational database that I have been illustrating, I decided on specific information that I needed to carry. Before I can decide on the tables that I need, I have to put the data into third normal form:

Identification numberNameStreet AddressCityStateZIPDate first donatedYearly goal for the donorContact person for the donorAmount of each contributionDate the contribution was madeDrive number the contribution was made toDrive nameChairperson of the driveHow much money the drive made last yearHow much money the drive made this year

Page 5: Relational databases and third normal form As always click on speaker notes under view when executing to get more information!

Identification numberNameStreet AddressCityStateZIPDate first donatedYearly goal for the donorContact person for the donorAmount of each contributionDate the contribution was madeDrive number the contribution was made toDrive nameChairperson of the driveHow much money the drive made last yearHow much money the drive made this year

NormalizationNormalizationTo put the relationship into first normal form, I have to remove repeating groups.

Since a person can give many donations, the donations are a repeating group. The information about the donations needs to be removed.

This means I will need to develop two tables, one containing the donor information and one containing the donation information.

The nature of the data indicates a one to many relationship between the donor and the donations where one donor can make one or more donations, but a given donation has only one donor.

Page 6: Relational databases and third normal form As always click on speaker notes under view when executing to get more information!

NormalizationNormalization

Donor Information:

Identification numberNameStreet AddressCityStateZIPDate first donatedYearly goal for the donorContact person for the donor

Donation Information:

Identification NumberAmount of each contributionDate the contribution was madeDrive number the contribution was made toDrive nameChairperson of the driveHow much money the drive made last yearHow much money the drive made this year

The identification number must be carried with the donor information to identify the donor and it must be carried with the donation information to identify who gave each donation.

In addition, carrying the identification number on both tables provides a link between them.

On the donor information table, the identification number uniquely defines each record/row in the table so it is the primary key.

Page 7: Relational databases and third normal form As always click on speaker notes under view when executing to get more information!

NormalizationNormalization

Donation Information:

Identification NumberAmount of each contributionDate the contribution was madeDrive number the contribution was made toDrive nameChairperson of the driveHow much money the drive made last yearHow much money the drive made this year

First, I need to determine the key to this table. The identification number of the donor alone does not provide a key because a donor can give multiple donations. The identification number along with the drive number defines the key only if each donor can only give to a drive one time. If we are going to allow each donor to give to the same drive multiple times we need a third component such as the date the donation was made to uniquely define each record or row on the table.

The primary key for the donation table is:

Identification NumberDrive number the contribution was made toDate the contribution was made

Page 8: Relational databases and third normal form As always click on speaker notes under view when executing to get more information!

NormalizationNormalization

Donation Information:

Identification NumberDrive number the contribution was made toDate the contribution was madeAmount of each contributionDrive nameChairperson of the driveHow much money the drive made last yearHow much money the drive made this year

Primary key

On further analysis, it is clear that the donation information is not in second normal form because there are parts of the store that are dependent on only one part of the key. In particular, all of the information about the drive itself is dependent only on the drive number. We need to separate out this information.

The amount of each contribution can stay on the donor information table because it is dependent on all three parts of the primary key. It is dependent on the identification number to define who gave the donation, it is dependent on the drive number to tell which drive the donation was made to and it is dependent on the date of the contribution to differentiate it from other contributions made by that donor to that drive.

Page 9: Relational databases and third normal form As always click on speaker notes under view when executing to get more information!

Donor Information:

Identification numberNameStreet AddressCityStateZIPDate first donatedYearly goal for the donorContact person for the donor

NormalizationNormalization

Donation Information:

Identification NumberDrive number the contribution was made toDate the contribution was madeAmount of each contribution

Primary key

Drive Information:

Drive numberDrive nameChairperson of the driveHow much money the drive made last yearHow much money the drive made this year

The key for the Drive Information table is drive number. All of the other information in the table is dependent on the drive number.

Page 10: Relational databases and third normal form As always click on speaker notes under view when executing to get more information!

NormalizationNormalization

Donor Information:

Identification numberNameStreet AddressCityStateZIPDate first donatedYearly goal for the donorContact person for the donor - contact idContact nameContact phone number

To illustrate third normal form, lets say that we were carrying contact name and contact phone number as well as the contact id. We are now in violation of third normal form because contact name and contact phone number are dependent on contact id no on the identification number of the donor.

We would need to pull out the contact information and establish a contact information table.

Contact Information:

Contact idContact nameContact phone number

Donor Information:

Identification numberNameStreet AddressCityStateZIPDate first donatedYearly goal for the donorContact person for the donor - contact id