Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND

advertisement
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)
Queries

Query languages Structured Query
Language (SQL)
Basic format of query
 SELECT attributes
 FROM tables
 WHERE criteria
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
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
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?
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
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?
Queries

Specifying criteria with
multiple conditions:
Template for expressing
query design
Complex queries and the
navigation template
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
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?
Types of Reports
Report layout:
 Most reports have:
 Report header
 Page header
 Page footer
 Report footer
 Report details section
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
Types of Reports
Report layout:
 Grouped detail reports –
 Grouped by something
(the grouping
attribute)
 Contain:
 Group header
 Group detail
 Group footer
Types of Reports
Report content
Report organization
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
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
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
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
Event Reports
Single event report:
 Details about a single
event
 Often printed for
documentation or to give
to customers or suppliers
Reference Lists and
Status Reports


Focus on providing
information about
products, services, or
agents
Criteria can be used to
restrict the output
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
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
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
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
Appendix:




Using navigation templates
to design queries:
For more complicated
queries
To document the reasoning
behind the query design
Navigation template:
A problem-solving aid
Helps document how to
assemble information from
various tables in response
to a query
Appendix

Navigation template:
Two basic ways to identify
information from tables
1. 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
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
KEYTERMS







Database management
system (DBMS)
FROM
Event summary report
Group footer
Group header
Grouped detail report
Grouped detail status
reports
KEYTERMS







Grouped event detail
reports
Label boxes
Page footer
Page header
Query
Query by example (QBE)
Reference lists
KEYTERMS









Report
Report details
Report footer
Report header
SELECT
Simple event lists
Simple list
Single entity report
Single event report
KEYTERMS







Single
product/service/agent
status reports
Status reports
Structured query
language (SQL)
Summary report
Summary status reports
Text boxes
WHERE
Download