Download presentation
Presentation is loading. Please wait.
1
Advanced Database Concepts: Reports & Views
INFO/CSE 100, Spring 2006 Fluency in Information Technology 2/25/2019 fit advdatabases © 2006 University of Washington
2
Readings and References
Fluency with Information Technology Chapter 16, Case Study in Database Design References MS Access Help files keyword “form” Section “Reports and Report Snapshots” 2/25/2019 fit advdatabases © 2006 University of Washington
3
fit100-25-advdatabases © 2006 University of Washington
Views as Tables Recall that the result of a query is a table We have been presenting the table to the user in simple tabular form 2/25/2019 fit advdatabases © 2006 University of Washington
4
But tables are not pretty …
Users need help understanding what they are looking at and what they can do with it … … so we developed Forms for controlling the display of data for the user who is reviewing or updating specific records. 2/25/2019 fit advdatabases © 2006 University of Washington
5
Views as Forms A form is primarily used to enter or display data in a database Last lecture we developed Forms for better display to the user while updating the table. 2/25/2019 fit advdatabases © 2006 University of Washington
6
But forms are not very compact …
Users like to have reports densely packed with information and logically arranged … So this lecture we will develop Reports for compact display of multiple records. 2/25/2019 fit advdatabases © 2006 University of Washington
7
fit100-25-advdatabases © 2006 University of Washington
Reports A Report is another face for a table (or query) The report lets the designer arrange the data, label it, provide some control over events, etc the presentation multiple presentations are possible depending on the specific needs of each user Underlying data comes from a table or a query the content single source of data ensures consistency 2/25/2019 fit advdatabases © 2006 University of Washington
8
How does a report get built?
The New Report wizard can build a complete report for you. 2/25/2019 fit advdatabases © 2006 University of Washington
9
But this wizard is kind of naïve …
2/25/2019 fit advdatabases © 2006 University of Washington
10
You might want to use the Report Wizard instead since it gives you more control.
11
Better looking report, but you still probably want to tweak it …
12
But you probably want to tweak it …
14
Explore the Design capabilities
Properties of the various controls can be set Controls and labels can be moved around Images and patterns can be applied Totals, averages, subtotals etc can be calculated Information can be grouped by selected fields Etc, etc – there is a lot of flexibility in how these reports get generated 2/25/2019 fit advdatabases © 2006 University of Washington
15
entity-relationship diagram for Library database
Price Name ISBN Title ID Phone ∞ WrittenBy ∞ Books Authors ∞ PublisherOf 1 Publishers entity-relationship diagram for Library database Books, Publishers, Authors are tables Price, ISBN, Title are attributes of the table Books There is a relationship between Books and Publishers 1 Publisher can have many Books ID Phone Name
16
fit100-25-advdatabases © 2006 University of Washington
Create a new database We are going to be using MS Access. Its available on the Lab machines and in MS Office if you have that installed on your home computer already. Step 1: create a new database , with a .mdb file extension 2/25/2019 fit advdatabases © 2006 University of Washington
17
Create a new table in the database
MS Access tries to be friendly and offer you some choices! Select "Create table in Design View". Do not use the Wizard! 2/25/2019 fit advdatabases © 2006 University of Washington
18
Creating a table in Design view
Aha! Now you've got to enter in the attributes {fields} of the table. Attributes have a field name, data type, and a description. In this example, three fields are being created: ISBN, Title, and Price. ISBN field is specified as the key (see key icon). Remember that the key field must be unique! 2/25/2019 fit advdatabases © 2006 University of Washington
19
fit100-25-advdatabases © 2006 University of Washington
Entering Table Data Once the table has been added you must view leave the Design View to enter data into the table. 2/25/2019 fit advdatabases © 2006 University of Washington
20
fit100-25-advdatabases © 2006 University of Washington
Build another table 2/25/2019 fit advdatabases © 2006 University of Washington
21
Add publisher ID to books
Field properties allow you to add more details about each attribute {field}, including things like size, format (for dates), number of decimal places, required, etc… 2/25/2019 fit advdatabases © 2006 University of Washington
22
Create the link between the tables
From the Relationships view. We can create a link by dragging a line between a field from one table to a field on another table. 2/25/2019 fit advdatabases © 2006 University of Washington
23
Hey presto, we have a database!
Price Name ISBN Title ID Phone ∞ WrittenBy ∞ Books Authors ∞ PublisherOf 1 Publishers Hey presto, we have a database! ID Phone Name
24
Two tables with a relationship
2/25/2019 fit advdatabases © 2006 University of Washington
25
fit100-25-advdatabases © 2006 University of Washington
Create a query Create a query in Design View. Step 1: select query from the object lists. Step 2: select the tables you want to query from. Step 3: select the fields you want to query from. 2/25/2019 fit advdatabases © 2006 University of Washington
26
The query produces a new (virtual) table
A query produces a new table, of which we see the results. 2/25/2019 fit advdatabases © 2006 University of Washington
27
Project (select particular columns)
2/25/2019 fit advdatabases © 2006 University of Washington
28
Select particular rows
2/25/2019 fit advdatabases © 2006 University of Washington
29
fit100-25-advdatabases © 2006 University of Washington
SQL behind the scenes Books.ISBN == books table and ISBN field Books.* all fields from the books table!! 2/25/2019 fit advdatabases © 2006 University of Washington
30
Recall: Structure of the database
A database contains one or more tables Tables include entities with attributes There are relationships defined between the entities in the various tables Retrieve information from the tables using queries We designed and partially implemented a simple library database 2/25/2019 fit advdatabases © 2006 University of Washington
31
Books Authors Publishers Price Name ISBN Title ID Phone ∞ WrittenBy ∞
PublisherOf 1 Publishers ID Phone Name
32
What is the relationship?
This relationship is 1-to-many: One publisher is responsible for many books. Each book has only one publisher. Books ∞ PublisherOf The two tables are joined using the publisher ID number. The publisher ID is the primary key for each entry in the publishers table. Therefore, each publisher must have a unique publisher ID. The publisher ID is a foreign key for each entry in the books table and we have requested referential integrity Therefore, the given publisher ID must exist in the publishers table. 1 Publishers 2/25/2019 fit advdatabases © 2006 University of Washington
33
Referential Integrity
2/25/2019 fit advdatabases © 2006 University of Washington
34
PubID must reference an actual publisher
2/25/2019 fit advdatabases © 2006 University of Washington
35
What is the relationship?
Price Name ISBN Title ID Phone ∞ WrittenBy ∞ Books Authors This relationship is many-to-many: One book may have several authors. One author may have written several books. We need a unique identifier for each book. We already selected the ISBN as the primary key and asked Access to make sure that there are no duplicates We need a unique identifier for each author We will define an author table with a unique ID for each author 2/25/2019 fit advdatabases © 2006 University of Washington
36
fit100-25-advdatabases © 2006 University of Washington
authors table 2/25/2019 fit advdatabases © 2006 University of Washington
37
Link one book with many authors?
We DO want: to link each book to one or more authors We DON'T want to specify extra fields (author1, author2, author3,…) this is wasteful and limits the max number of authors to specify each book entry several times, naming a different author in each row this duplicates all the other information about the book 2/25/2019 fit advdatabases © 2006 University of Washington
38
Add a cross-reference table!
Refine the design so that it includes another table that is a book-author cross reference Each entity in the table is a single cross reference Attribute: ISBN Attribute: Author ID No primary key Now we can break the many-to-many relationship into two 1-to-many relationships that we already know how to implement 2/25/2019 fit advdatabases © 2006 University of Washington
39
Define new cross-reference entities
Price Name ISBN Title ID Phone 1 ∞ ∞ 1 Books Book/Author Authors ISBN AuthorID 2/25/2019 fit advdatabases © 2006 University of Washington
40
fit100-25-advdatabases © 2006 University of Washington
book-author table 2/25/2019 fit advdatabases © 2006 University of Washington
41
Define the new relationships
2/25/2019 fit advdatabases © 2006 University of Washington
42
Define a query that uses the relationship
Query By Example actual SQL
43
Get the new view of the data
Notice that this view has redundant data That's okay, because we are not storing it this way, just presenting it The redundant items (Alex, Another Press) came from a single entry in a table – they are guaranteed to be identical 2/25/2019 fit advdatabases © 2006 University of Washington
44
Now we've implemented this entire schema.
Price Name ISBN Title ID Phone ∞ WrittenBy ∞ Books Authors ∞ PublisherOf 1 Now we've implemented this entire schema. Publishers ID Phone Name
45
View: All Books from “Another Press”
46
fit100-25-advdatabases © 2006 University of Washington
View: All Books by Alex 2/25/2019 fit advdatabases © 2006 University of Washington
47
View: All info about a given ISBN
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.