1 project 10 database queries— textbook database management information systems, 9 th edition, by...

45
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.

Upload: christopher-mckinney

Post on 18-Jan-2016

230 views

Category:

Documents


1 download

TRANSCRIPT

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

1

PROJECT 10DATABASE QUERIES—TEXTBOOK DATABASE

Management Information Systems, 9th edition,By Raymond McLeod, Jr. and George P. Schell

© 2004, Prentice Hall, Inc.

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

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.

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

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

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

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

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

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

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

6

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

7

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

8

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

9

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

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

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

11

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

12

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

13

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

14

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

15

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

16

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

17

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

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

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

19

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

20

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

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

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

22

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

23

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

24

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

25

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

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

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

27

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

28

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

29

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

30

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

31

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

32

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

33

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

34

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

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

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

36

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

37

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

38

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

39

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

40

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

41

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

42

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

43

ASSIGNMENT1. 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.”

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

44

ASSIGNMENT6. 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.

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

45

END OF PROJECT 10