32
Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Embed Size (px)

Citation preview

Page 1: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Chapter 6UNDERSTANDING AND DESIGNINGQUERIES AND REPORTS

Page 2: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Queries

Query languages – Enable users to

communicate with the DBMS in more structured formats

Structured query language (SQL)

Query by example (QBE)

Page 3: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Queries

Query languages - Structured Query Language (SQL)

Basic format of query SELECT attributes FROM tables WHERE criteria

Page 4: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Queries

Query languages – Structured Query Language (SQL)

Format allows: Specifying attributes

to include in the output

Accessing data from tables based on a condition

Specifying tables from which attributes used in the criteria can be obtained

Page 5: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Queries

Query languages – Query by Example (QBE):

Simpler but less powerful approach for communicating with the database

Specify the desired output from one or more tables using a grid Enter name of each desired

attribute (field) into a different column in the grid

Enter selection criteria in the appropriate attribute’s column

User doesn’t have to learn details of SQL

Page 6: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Queries

Query specification: Single table queries –

Two sets of questions:1. What attributes do users require in the query output? What tables contain the attributes required?2. What criteria will be used to generate the output? What attributes will be used in the criteria? What tables contain the attributes needed?

Page 7: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Queries

Query specification: Single table queries –

Once queries are answered, either

Use a QBE grid to specify the given information to the DBMS or

Express the information in a SQL statement

Page 8: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Queries

Query specification: Multiple table queries –

Make sure the different tables in the query are properly linked to each other

Answer question # 3 – What foreign keys link the information in a table to the primary keys of other tables in the query?

Page 9: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Queries

Specifying criteria with multiple conditions:

Template for expressing query design

Complex queries and the navigation template

Page 10: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Types of Reports

4 reports based on the organization of the data - Simple list Grouped detail Summary Single entity

Reports can be based on the type of data

Page 11: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Types of Reports

Need to review the format (layout) of a report.

Then, consider the following questions related to report design: What data are

included in a report? How are the data

organized?

Page 12: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Types of Reports

Report layout: Most reports have:

Report header Page header Page footer Report footer Report details

section

Page 13: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Types of Reports

Report layout: Two important elements

of any report: Label boxes

Display descriptive text

Unaffected by table data

Static - do not change when underlying data changes

Text boxes Display data taken or derived from a table

Depends on current contents of table

Dynamic

Page 14: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Types of Reports

Report layout: Grouped detail reports

– Grouped by

something (the grouping attribute)

Contain: Group header Group detail Group footer

Page 15: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Types of Reports

Report content

Report organization

Page 16: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Event Reports

List or summarize event data available in transaction tables

Draw on data available in transaction tables for most of their content

Criteria are used to restrict output to specific events

Page 17: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Event Reports

Report should show criteria used to select information

Report header should show starting and ending dates of the events

Simple event lists: Simple listing of events

during a time period organized by event date or transaction #

No grouping or subtotals

Page 18: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Event Reports

Grouped event detail reports:

List of events during a period

Commonly grouped by products/services or agents

Subtotals are often reported

Easier to analyze than ungrouped reports

Page 19: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Event Reports

Event summary report: Summarizes event data

by various parameters May be superior to

grouped event detail reports when a large number of groups needs to be reported

Page 20: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Event Reports

Single event report: Details about a single

event Often printed for

documentation or to give to customers or suppliers

Page 21: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Reference Lists and Status Reports

Focus on providing information about products, services, or agents

Criteria can be used to restrict the output

Page 22: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Reference Lists and Status Reports

4 report models focus on organizing and summarizing master table data Reference lists Grouped detail

status reports Summary status

reports Single

product/service/agent status reports

Page 23: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Reference Lists and Status Reports

Reference lists: Report only reference

data that are taken from master tables

Information about balances or quantity on hand not included in reports

Page 24: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Reference Lists and Status Reports

Status reports: Summary data about

products, services, agents Grouped detail status

reports Display summary data,

usually some reference data, and supporting details

Draw on event and product/service/agent records

Usually list one type of event

Page 25: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Reference Lists and Status Reports

Status reports: Summary status reports

List reference and summary data about products/services/agents

Summarize the status of the product, service, agent

Single product/service/agent status reports Provide detailed data Include both reference

and summary data for a single entity

Page 26: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Appendix:

Using navigation templates to design queries:

For more complicated queries

To document the reasoning behind the query designNavigation template:

A problem-solving aid Helps document how to

assemble information from various tables in response to a query

Page 27: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Appendix

Navigation template: Two basic ways to identify

information from tables1. Identify records that

satisfy a certain condition – criterion is based on attributes of a single table

2. Identify records where a value in the attribute of one table matches the value of an attribute in another table - criterion requires information from multiple tables

Page 28: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

Appendix

Navigation template: Helps avoid errors in

query construction Forces careful thinking

about required tables Omitting required tables

or adding unnecessary tables may result in incorrect answers

When template is completed Construct actual query Query design template

can summarize design of query

Page 29: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

K E Y T E R M S

Database management system (DBMS)

FROM Event summary report Group footer Group header Grouped detail report Grouped detail status

reports

Page 30: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

K E Y T E R M S

Grouped event detail reports

Label boxes Page footer Page header Query Query by example

(QBE) Reference lists

Page 31: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

K E Y T E R M S

Report Report details Report footer Report header SELECT Simple event lists Simple list Single entity report Single event report

Page 32: Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS

K E Y T E R M S

Single product/service/agent status reports

Status reports Structured query

language (SQL) Summary report Summary status

reports Text boxes WHERE