Access Database Library Assignment
description
Transcript of Access Database Library Assignment
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
Book Customer
M
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!
Book Customer
M
So we have a many to many relationship!
Book Customer
M M
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
customer checkout book
1 M 1M
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?