the university of akron dept of business technology computer information systems
DESCRIPTION
The University of Akron Dept of Business Technology Computer Information Systems. The Relational Model: Query-By-Example (QBE). 2440: 180 Database Concepts Instructor: Enoch E. Damson. Query-by-Example (QBE). Query Questions represented in a way the DBMS can recognize and process QBE - PowerPoint PPT PresentationTRANSCRIPT
The University of AkronThe University of AkronDept of Business TechnologyDept of Business Technology
Computer Information SystemsComputer Information Systems
The Relational Model:The Relational Model:
Query-By-Example (QBE)Query-By-Example (QBE)
2440: 1802440: 180Database ConceptsDatabase Concepts
Instructor: Enoch E. DamsonInstructor: Enoch E. Damson
2The Relational Model: QBE
Query-by-Example (QBE)Query-by-Example (QBE) Query Query
Questions represented in a way the DBMS Questions represented in a way the DBMS can recognize and processcan recognize and process
QBE QBE
Visual approach to writing queriesVisual approach to writing queries
Used in MS-AccessUsed in MS-Access
3The Relational Model: QBE
Figure 2.3: An Example of Simple Queries
4The Relational Model: QBE
Figure 2.4: Simple Queries…
5The Relational Model: QBE
Simple CriteriaSimple Criteria Criteria – conditions that data must satisfyCriteria – conditions that data must satisfy
Criterion – a single conditionCriterion – a single condition
To display specific query results, enter the To display specific query results, enter the condition in the appropriate column in the condition in the appropriate column in the design griddesign grid
6The Relational Model: QBE
Query with Simple Criteria
7The Relational Model: QBE
Comparison (Relational) Comparison (Relational) OperatorsOperators
Finds something other than an exact matchFinds something other than an exact match
Comparison operators are:Comparison operators are:
= (equal to)= (equal to)
> (greater than)> (greater than)
< (less than)< (less than)
>= (greater than or equal to)>= (greater than or equal to)
<= (less than or equal to)<= (less than or equal to)
NOT (not equal to)NOT (not equal to)
8The Relational Model: QBE
Compound CriteriaCompound Criteria
Combines comparison operatorsCombines comparison operators
Many languages use AND or OR between Many languages use AND or OR between the separate criteriathe separate criteria
In an AND criterion, both criteria must be In an AND criterion, both criteria must be truetrue
In an OR criterion, the overall criterion is In an OR criterion, the overall criterion is true if either of the individual criteria is true if either of the individual criteria is truetrue
9The Relational Model: QBE
Query Using AND Criteria
10The Relational Model: QBE
Query Using OR Criteria
11The Relational Model: QBE
Computed FieldsComputed Fields You can include calculated fields that are You can include calculated fields that are
not in the database in queriesnot in the database in queries
Computed field (calculated field) – a field Computed field (calculated field) – a field that is the result of a calculation using one that is the result of a calculation using one or more existing fieldsor more existing fields
In a query that uses computed fields, if a In a query that uses computed fields, if a field name contains spaces you must field name contains spaces you must enclose it in square bracketsenclose it in square brackets
12The Relational Model: QBE
Query Using Computed Field
13The Relational Model: QBE
Calculating StatisticsCalculating Statistics
CountCount
SumSum
Avg (average)Avg (average)
Max (largest value)Max (largest value)
Min (smallest value)Min (smallest value)
StDev (standard StDev (standard deviation)deviation)
Var (variance)Var (variance)
FirstFirst
LastLast
Built-in statistics (called aggregate functions in Access) include:
14The Relational Model: QBE
Query to Calculate an Average
15The Relational Model: QBE
GroupingGrouping
Grouping – creating groups of records Grouping – creating groups of records that share some common characteristicthat share some common characteristic
Functions can be used in combination Functions can be used in combination with grouping where statistics are with grouping where statistics are calculated for groups of recordscalculated for groups of records
16The Relational Model: QBE
SortingSorting Sorting – listing records in a query’s results in Sorting – listing records in a query’s results in
a particular waya particular way It is possible to sort using more than one fieldIt is possible to sort using more than one field Sort Key – the field on which records are Sort Key – the field on which records are
sortedsorted Major sort key (primary sort key) – the more Major sort key (primary sort key) – the more
important fieldimportant field Minor sort key (secondary sort key) – the less Minor sort key (secondary sort key) – the less
important fieldimportant field Major sort key is on the left of the grid and the Major sort key is on the left of the grid and the
minor sort key is on the rightminor sort key is on the right
17The Relational Model: QBE
Query to Sort Records
18The Relational Model: QBE
Query to Sort on Multiple Keys
19The Relational Model: QBE
Query to Sort on Multiple Keys…
20The Relational Model: QBE
Joining TablesJoining Tables Queries to select data from more than one tableQueries to select data from more than one table
Join the tables based on matching fields in Join the tables based on matching fields in corresponding columnscorresponding columns
In an Access query, a join line between In an Access query, a join line between matching fields in the two tables will be created matching fields in the two tables will be created indicating how the tables are relatedindicating how the tables are related
When joining multiple tablesWhen joining multiple tables
Add all the tables involved to the upper paneAdd all the tables involved to the upper pane
Add the query results grid in the desired orderAdd the query results grid in the desired order
21The Relational Model: QBE
Query to Join Table
22The Relational Model: QBE
Query to Join Tables…
23The Relational Model: QBE
Update QueryUpdate Query
Update query – a query that changes dataUpdate query – a query that changes data
Makes a specified change to all records Makes a specified change to all records satisfying the criteria in the querysatisfying the criteria in the query
In Access, a new row is created that is In Access, a new row is created that is used to indicate how to update the data used to indicate how to update the data selected by the queryselected by the query
24The Relational Model: QBE
Update Query
25The Relational Model: QBE
Delete QueryDelete Query Queries can be used to delete one or more Queries can be used to delete one or more
records at a timerecords at a time
Delete query – deletes all the records Delete query – deletes all the records satisfying the criteria entered into the satisfying the criteria entered into the queryquery
When you change the Query type to Delete When you change the Query type to Delete Query, an extra row, called a Delete row, Query, an extra row, called a Delete row, is added to the design gridis added to the design grid
26The Relational Model: QBE
Delete Query
27The Relational Model: QBE
Make-Table QueryMake-Table Query
Queries can be used to create a new table Queries can be used to create a new table in either the current database or in a in either the current database or in a separate databaseseparate database
Make-table query – creates a new table Make-table query – creates a new table using the query resultsusing the query results
The data added to the new table is The data added to the new table is separate from the original table in which separate from the original table in which it appearsit appears
28The Relational Model: QBE
Make-Table Query
29The Relational Model: QBE
Make-Table Query…