Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 PROJECT 10 DATABASE QUERIES— TEXTBOOK DATABASE Management Information Systems, 9 th edition, By Raymond McLeod, Jr. and George P. Schell © 2004, Prentice.

Similar presentations


Presentation on theme: "1 PROJECT 10 DATABASE QUERIES— TEXTBOOK DATABASE Management Information Systems, 9 th edition, By Raymond McLeod, Jr. and George P. Schell © 2004, Prentice."— Presentation transcript:

1 1 PROJECT 10 DATABASE QUERIES— TEXTBOOK DATABASE Management Information Systems, 9 th edition, By Raymond McLeod, Jr. and George P. Schell © 2004, Prentice Hall, Inc.

2 2 Learning Objectives Learn to create queries using one or multiple tables. Understand how to limit query results with single and multiple constraints. Understand how a query can request constraint values from the query user. Learn to use queries that look for partial values in fields. Learn to make computations within queries on both numeric and text fields.

3 3 Introduction This project uses Access 2002 (also known as Access XP) to create queries for an existing database The database for this project, Textbook, concerns classes and the books used in those classes. The database also contains records of students who have copies of books to sell Although there may be many tables in a database, they are all contained in the single database file along with any queries, reports, or other components of the database You should create a copy of the data file with your database on a regular basis

4 4 EXAMPLE This example will generate a number of queries from the Textbook database The Textbook database will be provided by your instructor or downloaded from the Prentice Hall Web site Managers typically use queries to look for specific records, and so the query is constrained to records that have certain values for fields Other queries compute new values from the values of other fields in the query

5 5 Textbook Database The Textbook database consists of four tables that relate to each other by common values The tables and their data fields are shown in Figure P10.1 The STUDENT table contains four fields: FirstName, LastName, BookNumb, and CopiesToSell. The key fields of the tables are shown in bold font It takes the combination of values from the FirstName, LastName, and BookNumb fields to make a key (i.e., a unique value) for the STUDENT table The ClassNumb field is the only field needed to be the key of the CLASS table

6 6

7 7

8 8

9 9

10 10 Creating a Query with Constraints Records in the BOOK table are shown in Figure P10.5 If a query were constructed without constraints, all of the records in the table would be displayed in the query result It is more productive to restrict the records displayed to those which fit some decision making criteria

11 11

12 12

13 13

14 14

15 15

16 16

17 17

18 18 Parameter Query Sometimes the decision maker will know which field will constrain a query but not the value of the constraint Access allows parameter queries, queries that let a user provide a value as the query runs. For example, suppose the decision maker is looking for unusually low or high book prices A decision maker could code the price amounts into the query as in Figure P10.11 or the query code could be written so that the decision maker is asked to provide the amounts each time the query runs

19 19

20 20

21 21 Inexact Constraints Constraints on fields containing text can be difficult to create because what constitutes a match might be ambiguous For example, what if you are looking for an author named “Tattem?” You can see from the values of the Author field in Figure P10.3 that Tattem is a coauthor of two books If the constraint is entered as Figure P10.14, Access will not find the record as the “Tattem” phrase looks for an exact match for the entire field value in the database records and, since “Tattem” is not an exact match of an entire Author field, no records are displayed by the query

22 22

23 23

24 24

25 25

26 26 Queries Requiring more than One Table Queries that require data fields from more than one table require that the tables supplying field values as well as tables used to navigate between those tables be included in the query-by-example. For example, assume you wish to create a query that displays the class number and the titles of books used for the class The ClassNumb field is needed from the CLASS table and the Title field is needed from the BOOK table

27 27

28 28

29 29

30 30

31 31

32 32

33 33

34 34

35 35 Data Field Concatenation and Calculation Data fields with text values can be concatenated— the characters can be added together with other characters and other text fields Numeric fields are subject to mathematical operations These operations can take place within a query so that values in the database do not need to be changed

36 36

37 37

38 38

39 39

40 40

41 41

42 42

43 43 ASSIGNMENT 1. Create a query using the CLASS table that shows the class number and enrollment where the enrollment is less than 25 students. Sort the results by the class number field. 2. Create a query that shows the class number (sorted) of classes that have either less than 25 students or more than 100 students. Show only the ClassNumb field, not the field or fields you use to constrain the results. 3. Create a query that shows the class number (sorted) of classes that have an enrollment of greater than 25 and less than 100 students. Show only the ClassNumb field in the query results. 4. Create a query that displays all of the MIS classes. These classes will begin the ClassNumb field with “MIS” and you should use an inexact constraint match. 5. Create a query that finds all senior level classes in the CLASS table based upon values in the ClassNumb field. A senior level class will always have the fourth character of the ClassNumb field be the value “4.”

44 44 ASSIGNMENT 6. Make a parameter query that asks the user to provide a ClassNumb value and limit the query results to the ClassNumb and Enrollment field values for that class. 7. What books are not being sold by any student? Show the book title (sorted) and book number. 8. For each class, count the number of books used in the class. Show the class number (sorted) and the count of the books. For this query you need two tables. 9. Sum the number of copies of all books that each student has to sell. The student name should be in first name, last name format such that one field (called “Name”) is created as the first name, a blank space, and the last name. Sort by the “Name” field you create. 10. Which book has the highest price? Show the book title and author.

45 45 END OF PROJECT 10


Download ppt "1 PROJECT 10 DATABASE QUERIES— TEXTBOOK DATABASE Management Information Systems, 9 th edition, By Raymond McLeod, Jr. and George P. Schell © 2004, Prentice."

Similar presentations


Ads by Google