Library Assignment
Let's try to understand one simple database
A library allows customers to check out books
So what tables do we need?
Customer table: any data the library needs to keep about its customers
Customer table primary key: Autonumber
Book table: store any data the library needs to keep about its books
Primary key for book table
Is there a relationship between the book and customer table?
To see if 2 tables have a relationship you must ask 3 questions.
You have to ask 3 questions for each side of the relationship
Could you have a book in the book table that no one has checked out?
Could you have a book that 1 customer has checked out?
Could you have a book that more than 1 customer has checked out?
Since you can have a book checked out by more than one customer M Book Customer
Could you have a customer in the customer table that has not checked out a book?
Could you have a customer that has checked out 1 book?
Could you have a customer that has checked out more than 1 book?
This side of the relationship is also many! M Book Customer
So we have a many to many relationship! M M Book Customer
Each customer can check out more than one book and each book can be checked out by more than one customer
We can’t track which book a customer checks out without adding a new table.
To create a bridge table you start with the primary keys of the related tables
What should be the primary key for the bridge table?
Entity relationship diagram shows the relationship 1 M M 1 customer checkout book
But a customer can check out more than one book at a time!
So instead of creating a bridge table between customer and book tables we will create a check out table to show each time a customer checks out books.
So we need a table to show each time a customer checks out books…
…and another table to show exactly what books that customer checked out that day
The Checkout_Book table would be the bridge or junction table here for the Book and Checkout tables many to many relationship.
To enter data in this database
You could not enter data about a customer checking out a book if…
Questions?
Access Database Library Assignment
Access Database Library Assignment

Access Database Library Assignment

Editor's Notes

  • #13 The first 3 questions are asked from the book table looking at the customer table. Here the answer is yes. You could have a new book for example.
  • #14 Yes to this question.
  • #15 Again yes to this question.
  • #16 this side of the relationship is many and now we have to see what the other side of the relationship is.
  • #17 The next 3 questions are asked from the customer table looking at the book table. Here the answer is yes.
  • #18 Again yes!
  • #19 And yes again.
  • #20 Since a book could be checked out by more than one customer.
  • #27 If this database only had 3 tables then there would have to be another entry for each book each customer checked out. We can do better than that!
  • #28 So instead of a bridge table we will create a checkout table and bring the customer primary key over as the foreign key and also include a Date_Checked_Out field. To reduce errors and to save time we will have Access enter a default time of today for this field.What would be a good primary key for this table?
  • #29 This is a bridge or junction table so we need both primary keys of the 2 tables in the many to many relationship to serve as foreign keys and here they both can be the primary key. We can never use just one of these two foreign keys as the primary key. And sometimes there are good reasons not to use both foreign keys as the primary key. But here we can totally eliminate errors like accidently entering the same book two times by using both foreign keys as the primary key.