Access Database Library Assignment

35
Library Assignment

description

This presentation walks through some database theory on how to build a database for a library.

Transcript of Access Database Library Assignment

Page 1: Access Database Library Assignment

Library Assignment

Page 2: Access Database Library Assignment

Let's try to understand one simple database

Page 3: Access Database Library Assignment

A library allows customers to check out books

Page 4: Access Database Library Assignment

So what tables do we need?

Page 5: Access Database Library Assignment

Customer table: any data the library needs to keep about its customers

Page 6: Access Database Library Assignment

Customer table primary key: Autonumber

Page 7: Access Database Library Assignment

Book table: store any data the library needs to keep about its books

Page 8: Access Database Library Assignment

Primary key for book table

Page 9: Access Database Library Assignment

Is there a relationship between the book and customer table?

Page 10: Access Database Library Assignment

To see if 2 tables have a relationship you must ask 3 questions.

Page 11: Access Database Library Assignment

You have to ask 3 questions for each side of the relationship

Page 12: Access Database Library Assignment

Could you have a book in the book table that no one has checked out?

Page 13: Access Database Library Assignment

Could you have a book that 1 customer has checked out?

Page 14: Access Database Library Assignment

Could you have a book that more than 1 customer has checked out?

Page 15: Access Database Library Assignment

Since you can have a book checked out by more than one customer

Book Customer

M

Page 16: Access Database Library Assignment

Could you have a customer in the customer table that has not checked out a book?

Page 17: Access Database Library Assignment

Could you have a customer that has checked out 1 book?

Page 18: Access Database Library Assignment

Could you have a customer that has checked out more than 1 book?

Page 19: Access Database Library Assignment

This side of the relationship is also many!

Book Customer

M

Page 20: Access Database Library Assignment

So we have a many to many relationship!

Book Customer

M M

Page 21: Access Database Library Assignment

Each customer can check out more than one book and each book can be checked out by more than one customer

Page 22: Access Database Library Assignment

We can’t track which book a customer checks out without adding a new table.

Page 23: Access Database Library Assignment

To create a bridge table you start with the primary keys of the related tables

Page 24: Access Database Library Assignment

What should be the primary key for the bridge table?

Page 25: Access Database Library Assignment

Entity relationship diagram shows the relationship

customer checkout book

1 M 1M

Page 26: Access Database Library Assignment

But a customer can check out more than one book at a time!

Page 27: Access Database Library Assignment

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.

Page 28: Access Database Library Assignment

So we need a table to show each time a customer checks out books…

Page 29: Access Database Library Assignment

…and another table to show exactly what books that customer checked out that day

Page 30: Access Database Library Assignment

The Checkout_Book table would be the bridge or junction table here for the Book and Checkout tables many to many relationship.

Page 31: Access Database Library Assignment

To enter data in this database

Page 32: Access Database Library Assignment

You could not enter data about a customer checking out a book if…

Page 33: Access Database Library Assignment

Questions?

Page 34: Access Database Library Assignment
Page 35: Access Database Library Assignment