18
Relational example using donor, contrib and drive tables Please use speaker notes for additional information!

Relational example using donor, contrib and drive tables Please use speaker notes for additional information!

Embed Size (px)

Citation preview

Page 1: Relational example using donor, contrib and drive tables Please use speaker notes for additional information!

Relational example using donor, contrib and drive tables

Please use speaker notes for additional information!

Page 2: Relational example using donor, contrib and drive tables Please use speaker notes for additional information!

Access - Donor table

Access - Donor table

The primary key is the Idno which is a text field of 5 characters. Notice under Indexed it was set to Yes with No Duplicates.

Page 3: Relational example using donor, contrib and drive tables Please use speaker notes for additional information!

Keys - primaryKeys - primaryPRIMARY KEY

Each table should have a primary key that identifies one and only one record. Sometimes the primary key is one column/field, sometimes it is a combination of column/fields. In this example it is one column/field, the Idno.

In the donor table, it can be seen that there is a different Idno for each record/row. In other words, the Idno uniquely identifies a record/row.

Page 4: Relational example using donor, contrib and drive tables Please use speaker notes for additional information!

Access - contribu tableAccess - contribu table

The primary key is made up of Idno, DriveNo, DateCont. Note under Indexes these are named IdDr.

Page 5: Relational example using donor, contrib and drive tables Please use speaker notes for additional information!

Keys - primaryKeys - primary

In this example, the primary key is not as easy to determine. Clearly the Idno does not work as the primary key because there are multiple of the same Idno.

This means Idno needs to be combined with something else. If we combine it with DriveNo it will work if there is no record/row where the Idno plus the DriveNo are the same.

In this example it will not work because the same person has contributed to the same drive multiple times to the same drive. If we combine Idno plus DriveNo plus DateCont as the primary key we will be okay as long as we decide that the same donor cannot contribute to the same drive twiceon the same date. That is reasonable so we will go with the combination of those three fields to make the primary key.

Page 6: Relational example using donor, contrib and drive tables Please use speaker notes for additional information!

Access - drive tableAccess - drive table

DriveNo is the primary key. It is indexed with no duplicates.

Page 7: Relational example using donor, contrib and drive tables Please use speaker notes for additional information!

Keys - primaryKeys - primary

In this example, the primary key is DRIVENO. DRIVENO uniquely defines each record/row in the table. Another drive with the same drive number would not make sense in this table.

Page 8: Relational example using donor, contrib and drive tables Please use speaker notes for additional information!

The relationship or link between the donor table and the donation table is based on idno. In other words, the idno appears in both tables.

The relationship or link between the contribution table (contribu) and the drive table is based on driveno. In other words, the driveno appears in both tables.

NOTE: There is no direct link between the donor table and the drive table.

Page 9: Relational example using donor, contrib and drive tables Please use speaker notes for additional information!

Types of relationshipsTypes of relationships

In a relational database there are the following kinds of relationships:

•One to One

•One to Many

•Many to Many

Page 10: Relational example using donor, contrib and drive tables Please use speaker notes for additional information!

One to One relationship

One to One relationship One to One Relationship:

If the donation table only allowed one donation for every donor then we would have a one to one relationship.

Page 11: Relational example using donor, contrib and drive tables Please use speaker notes for additional information!

One to Many relationship

One to Many relationship One to Many Relationship:

In this example, one donor can give multiple donations but each donation only has one donor.

Page 12: Relational example using donor, contrib and drive tables Please use speaker notes for additional information!

Many to Many Relationship:In this example, each movie can have many stars and each star can have many movies, therefore this is a many to many relationship.

Many to many relationship

Many to many relationship

Bridge table - used with many to many.

Page 13: Relational example using donor, contrib and drive tables Please use speaker notes for additional information!

Keys - foreignKeys - foreign

The DriveNO on the contribution table is called a foreign key because it links into the primary key on the drive table.

Page 14: Relational example using donor, contrib and drive tables Please use speaker notes for additional information!

RelationshipsRelationships

As shown, DriveNo from Drive links to DriveNo from Contribu and Idno from Contribu links to Idno from Donor.

Page 15: Relational example using donor, contrib and drive tables Please use speaker notes for additional information!
Page 16: Relational example using donor, contrib and drive tables Please use speaker notes for additional information!

I clicked on Tools and then relationships. This is what I was given.

RelationshipsRelationships

I then added all three tables that are shown before selecting close.

Page 17: Relational example using donor, contrib and drive tables Please use speaker notes for additional information!

RelationshipsRelationships

I clicked on movieno under Movie and dragged it over to movieno under MovStar. The following screen appeared.

Page 18: Relational example using donor, contrib and drive tables Please use speaker notes for additional information!

RelationshipsRelationships

This shows the relationship between the three tables. There is a link between movieno on Movie and movieno on MovStar and another link between starno on Star and starno on MovStar.