35
1 A Guide to SQL, Sixth Edition Chapter 1 Introduction to Premiere Products and Henry Books

A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

Embed Size (px)

Citation preview

Page 1: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

1

A Guide to SQL, Sixth Edition

Chapter 1Introduction to Premiere Products and

Henry Books

Page 2: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

2

Objectives

Introduce Premiere Products, a company whose database is used as the basis for many of the examples throughout the text

Introduce Henry Books, a company whose database is used in the case that runs throughout the text

Page 3: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

3

The Premiere Products Database

Premiere Products is a distributor of appliances, housewares, and sporting goods

It is no longer feasible to maintain customer, order, and inventory data using its current manual system

Page 4: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

4

Benefits of a Computer Database System

Ensure that the data is current and more accurate than in the present manual system

Produce a variety of useful reports

Ask questions concerning the database and obtain answers easily and quickly

Page 5: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

5

Required Data for Sales Reps

Number

Last name

First name

Address

Total commission

Commission rate of each sales rep

Page 6: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

6

Required Data for Customers

Customer number

Last name

First name

Address

Current balance

Credit limit

The number of the sales rep who represents the customer

Page 7: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

7

Required Data for Parts

Part number

Part description

Number of units on hand

Item class

Number of the warehouse where the item is stored

Unit price for each part in the inventory

Page 8: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

8

Sample Order

Page 9: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

9

Components of Sample Order

Heading (top of the order) contains: Order number and dateCustomer’s number, name, and addressSales rep number and name

Body of the order contains a number of order lines called line items

Page 10: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

10

Components of Sample Order

Each order line contains: Part numberPart descriptionNumber of units orderedQuoted priceTotal, called ‘extension’

Footing (bottom of the order) contains the order total

Page 11: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

11

Item Information Stored for Each Order

Order number, date the order was placed, and the customer number of the customer who placed the order

Order number, part number, number of units ordered, and quoted price for each order line

Page 12: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

12

Overall Order Total

Overall order total is not stored as part of the database

Total order will be computed whenever an order is printed or displayed on the screen

Page 13: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

13

Sample Data for Premiere Products

Page 14: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

14

Sample Data for Premiere Products

Page 15: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

15

Sample Data for Premiere Products

Page 16: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

16

Sample Data for Premiere Products

Page 17: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

17

Sample Data for Premiere Products

Page 18: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

18

Sales Rep Information

Three sales representatives identified by numbers Example:Sales Rep Number: 20Name: Valerie KaiserAddress: 624 Randall, Grove, FL 33321Total commission: $20,542.50Commission rate: 5% (.05)

Page 19: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

19

Customer Information

Premiere Products has 10 customers who are identified with the numbers 148, 282, 356, 408, 462, 524, 608, 687, 725, and 842Example: Customer Number: 148 Name: Al’s Appliance and Sport Address: 2837 Greenway in Fillmore, FL 33336 Current Balance: $6,550.00 Credit Limit: $7,500.00 Sales Rep: 20

Page 20: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

20

Part Information

There are 10 parts identified by part numbers AT94, BV06, CD52, DL71, DR93, DW11, FD21, KL62, KT03, and KV29

Item class codes are HW (housewares), AP (appliances), and SG (sporting goods)

Page 21: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

21

Part Data Example

Example:Part Number: AT94Part Description: IronUnits on Hand: 50Item Class: HW (housewares)Warehouse Number: 3Unit Price: $24.95

Page 22: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

22

Order Information

Seven orders identified with the numbers 21608, 21610, 21613, 21614, 21617, 21619, and 21623Example:Order number: 21608Order date: October 20, 2003Customer number: 148 (Al’s Appliance and

Sport)

Page 23: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

23

Alternative ORDERS Table Structure

Page 24: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

24

Problem with Alternative ORDERS Table

Some of the individual positions within the table contain multiple entries

Multiple entries make it difficult to track the information between columns

Page 25: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

25

Practical Issues Raised by a Complex Table

How much room do you allow for these multiple entries?

What if an order has more order lines than you have allowed for?

Given a part, how do you determine which orders contain order lines for that part?

Page 26: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

26

ORDER_LINE Table Advantages

No multiple entries

Does not matter how many order lines exist for any order

Finding all the orders that contain order lines for a given part is easy

Page 27: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

27

Henry Books Database

Ray Henry is the owner of a bookstore chain named Henry Books

Ray has decided to store his data in a database because he wants to: Ensure that the data is current and accurate Produce several important reports Ask questions concerning the data and obtain

answers to these questions easily and quickly

Page 28: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

28

Information Gathered by Henry Books

Henry gathers and organizes information about: BranchesPublishersAuthorsBooks

Page 29: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

29

Types of Information

Each branch has a number that uniquely identifies the branch

In addition, Ray tracks the branch’s:NameLocationNumber of employees

Page 30: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

30

Types of Information

Each publisher has a code that uniquely identifies the publisher

In addition, Ray tracks the publisher’s:NameCity

Page 31: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

31

Types of Information

Each author has a number that uniquely identifies the author

In addition, Ray records each author’s:Last name First name

Page 32: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

32

Types of Information

Each book has a code that uniquely identifies the bookFor each book, Ray also tracks: TitlePublisherType of bookPriceWhether the book is a paperback or not

Page 33: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

33

Summary

Premiere Products is an organization whose information requirements include the following:Sales representativesCustomersOrdersPartsOrder lines

Page 34: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

34

Summary

The database for Henry Books contains the following information:BranchesPublishersBooksAuthors InventoryAuthor Sequence

Page 35: A Guide to SQL, Sixth Edition 1 Chapter 1 Introduction to Premiere Products and Henry Books

35

SQL Project One Completed

Good Luck

H. Zamanzadeh