Presentation is loading. Please wait.

Presentation is loading. Please wait.

The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Query-By-Example (QBE) 2440: 180 Database Concepts.

Similar presentations


Presentation on theme: "The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Query-By-Example (QBE) 2440: 180 Database Concepts."— Presentation transcript:

1 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

2 2The Relational Model: QBE Query-by-Example (QBE) Query Query Questions represented in a way the DBMS can recognize and process Questions represented in a way the DBMS can recognize and process QBE QBE Visual approach to writing queries Visual approach to writing queries Used in MS-Access Used in MS-Access

3 3The Relational Model: QBE Figure 2.3: An Example of Simple Queries

4 4The Relational Model: QBE Figure 2.4: Simple Queries…

5 5The Relational Model: QBE Simple Criteria Criteria – conditions that data must satisfy Criteria – conditions that data must satisfy Criterion – a single condition Criterion – a single condition To display specific query results, enter the condition in the appropriate column in the design grid To display specific query results, enter the condition in the appropriate column in the design grid

6 6The Relational Model: QBE Query with Simple Criteria

7 7The Relational Model: QBE Comparison (Relational) Operators Finds something other than an exact match Finds 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)

8 8The Relational Model: QBE Compound Criteria Combines comparison operators Combines comparison operators Many languages use AND or OR between the separate criteria Many languages use AND or OR between the separate criteria In an AND criterion, both criteria must be true In an AND criterion, both criteria must be true In an OR criterion, the overall criterion is true if either of the individual criteria is true In an OR criterion, the overall criterion is true if either of the individual criteria is true

9 9The Relational Model: QBE Query Using AND Criteria

10 10The Relational Model: QBE Query Using OR Criteria

11 11The Relational Model: QBE Computed Fields You can include calculated fields that are not in the database in queries You can include calculated fields that are not in the database in queries Computed field (calculated field) – a field that is the result of a calculation using one or more existing fields Computed field (calculated field) – a field that is the result of a calculation using one or more existing fields In a query that uses computed fields, if a field name contains spaces you must enclose it in square brackets In a query that uses computed fields, if a field name contains spaces you must enclose it in square brackets

12 12The Relational Model: QBE Query Using Computed Field

13 13The Relational Model: QBE Calculating Statistics Count Count Sum Sum Avg (average) Avg (average) Max (largest value) Max (largest value) Min (smallest value) Min (smallest value) StDev (standard deviation) Var (variance) First Last u Built-in statistics (called aggregate functions in Access) include:

14 14The Relational Model: QBE Query to Calculate an Average

15 15The Relational Model: QBE Grouping Grouping – creating groups of records that share some common characteristic Grouping – creating groups of records that share some common characteristic Functions can be used in combination with grouping where statistics are calculated for groups of records Functions can be used in combination with grouping where statistics are calculated for groups of records

16 16The Relational Model: QBE Sorting Sorting – listing records in a query’s results in a particular way Sorting – listing records in a query’s results in a particular way It is possible to sort using more than one field It is possible to sort using more than one field Sort Key – the field on which records are sorted Sort Key – the field on which records are sorted Major sort key (primary sort key) – the more important field Major sort key (primary sort key) – the more important field Minor sort key (secondary sort key) – the less important field Minor sort key (secondary sort key) – the less important field Major sort key is on the left of the grid and the minor sort key is on the right Major sort key is on the left of the grid and the minor sort key is on the right

17 17The Relational Model: QBE Query to Sort Records

18 18The Relational Model: QBE Query to Sort on Multiple Keys

19 19The Relational Model: QBE Query to Sort on Multiple Keys…

20 20The Relational Model: QBE Joining Tables Queries to select data from more than one table Queries to select data from more than one table Join the tables based on matching fields in corresponding columns Join the tables based on matching fields in corresponding columns In an Access query, a join line between matching fields in the two tables will be created indicating how the tables are related In an Access query, a join line between matching fields in the two tables will be created indicating how the tables are related When joining multiple tables When joining multiple tables Add all the tables involved to the upper pane Add all the tables involved to the upper pane Add the query results grid in the desired order Add the query results grid in the desired order

21 21The Relational Model: QBE Query to Join Table

22 22The Relational Model: QBE Query to Join Tables…

23 23The Relational Model: QBE Update Query Update query – a query that changes data Update query – a query that changes data Makes a specified change to all records satisfying the criteria in the query Makes a specified change to all records satisfying the criteria in the query In Access, a new row is created that is used to indicate how to update the data selected by the query In Access, a new row is created that is used to indicate how to update the data selected by the query

24 24The Relational Model: QBE Update Query

25 25The Relational Model: QBE Delete Query Queries can be used to delete one or more records at a time Queries can be used to delete one or more records at a time Delete query – deletes all the records satisfying the criteria entered into the query Delete query – deletes all the records satisfying the criteria entered into the query When you change the Query type to Delete Query, an extra row, called a Delete row, is added to the design grid When you change the Query type to Delete Query, an extra row, called a Delete row, is added to the design grid

26 26The Relational Model: QBE Delete Query

27 27The Relational Model: QBE Make-Table Query Queries can be used to create a new table in either the current database or in a separate database Queries can be used to create a new table in either the current database or in a separate database Make-table query – creates a new table using the query results Make-table query – creates a new table using the query results The data added to the new table is separate from the original table in which it appears The data added to the new table is separate from the original table in which it appears

28 28The Relational Model: QBE Make-Table Query

29 29The Relational Model: QBE Make-Table Query…


Download ppt "The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Query-By-Example (QBE) 2440: 180 Database Concepts."

Similar presentations


Ads by Google