Creating a Database in Access Creating a database involves 1.Logical design of tables and relationships 2.Physical design of tables and relationships 3.Populating tables
Logical Design of Library DB DB consists of these tables –Books (bkID, bkTitle, bkPrice) –Authors (auID, auName, auPhone) –Publishers (pubID, pubName, pubPhone)
Logical Design of Library DB Table Relationships Publishers pubID pubName pubPhone Books bkID bkTitle bkPrice pubID auID Authors auID auName auPhone
Physical Design of DB (Access) Create a new Database (e.g., myLibrary) Create tables Create fields –Go to design view –Insert fields –Select field types –Determine field properties Create more tables and their fields
Physical Design of DB (Access) Relate tables –Design Relationships –Connect key fields
Input Table Data Open a DB in Access (e.g., myLibrary) Open a table (e.g., publishers) Enter field data
Queries One table –Display publisher names and their phone numbers –Display book titles and their prices –Display author names and their phone numbers Two tables –Display book titles, their prices, and their publishers –Display book titles, their prices, and author names Three tables –Display book titles, their authors, and their publishers
Queries Which books are $25 or less? What is the phone number of publisher Big House? What is the phone number of Shakespeare? Who publishes the book Hamlet? All books published by Big House over $10.00 All books written by Shakespeare and their publisher
Additional Queries List all copywritten materials used in Illiad. List all special photographs used in Balloon. Display the author, publisher, and ISBN of Emma, and owners of all copywritten material What is the name of author Spencer’s wife? How many children does author Shakespeare have?
Modifying Database The current design allows only 1 author for each book. How can we allow more than 1 author for one book (e.g., co-authors)? Books bkID bkTitle bkPrice pubID auID Authors auID auName auPhone 1 ∞ Publishers pubID pubName pubPhone 1 ∞
Modifying Database Remember, every relationship between two tables must be 1-to-∞ or ∞-to-1. Solution: Introduce an artificial linking table between Books a ∞ nd Authors. Books bkID bkTitle bkPrice pubID auID Authors auID auName auPhone 1 ∞ BooksAuthors bkauID bkID auID ∞ 1 Publishers pubID pubName pubPhone
Logical Design of Library DB Table Relationships Publishers pubID pubName pubPhone Books bkID bkTitle bkPrice pubID auID Authors auID auName auPhone
Access Exercises Tables –Books –Authors –Publishers –BooksAuthors