Introduction to MIS
Chapter 6
Database Management Systems
Copyright © 1998-2002 by Jerry Post
Introduction to MIS
1
Database Management Systems
Reports and
ad hoc queries
Database
DBMS
Programs
Sales and transaction data
Introduction to MIS
2
Outline
Relational Databases
Queries
Designing a Database
Database Applications
Database Administration
Database and e-Business
Cases: Airlines
Appendix: Building Forms in Access
Introduction to MIS
3
DBMS & People
Database Administrator
(Standards, Design, and Control)
Programmer
Analyst
Data
Programs
& Revisions
Database
Management
System
Program
Business Needs
Ad Hoc Queries
Managers
and Reports
Program
Data Collection
and Transaction
Processing
Business Operations
Introduction to MIS
4
Relational Databases
Tables
Rows
Columns
Primary keys
Data types
Text
Dates & times
Numbers
Objects
Customer Table
Phone
312-555-1234
502-555-8876
602-555-9987
612-555-4325
Name
Jones
Smith
Juarez
Olsen
Introduction to MIS
City
Chicago
Glasgow
Phoenix
Minneapolis
Orders Table
Customer
502-555-8876
602-555-9987
612-555-4325
502-555-8876
Address
123 Main
456 Oak
887 Ribera
465 Thor
Date
3/3/04
4/4/04
4/9/04
5/7/04
Salesperson
2223
8876
8876
3345
Total_sale
157.92
295.53
132.94
183.67
5
Programming Approach
Problems with Programming
Data and programs
Undocumented files
Files & many programs
Multiuser
Changes
file 1
Invoice
Program
customers
Billing
Program
file A
file B
Introduction to MIS
6
Focus on data
Accuracy.
Time.
Concurrency.
Security.
Ad hoc queries
Speed of development
Change programs without
altering data.
Data integrity
Database Advantages
Data independence
Stable data
Programs change.
Report writers.
Input forms.
Data manipulation.
All Data Files
Database Management
System
Invoice
Program
Billing
Program
Flexibility & Queries
Introduction to MIS
7
Database Queries
Single Table
Computations
Joining Tables
Four questions to create a query
1)
2)
3)
4)
Introduction to MIS
What output do you want to see?
What tables are involved?
What do you already know? (constraints)
How are the tables joined?
8
File: C05E15a.mdb
Single Table Query Introduction
Sample Data
CID
28764
87535
44453
29587
Name
Adamz
James
Kolke
Smitz
Phone
602-999-2539
305-777-2235
303-888-8876
206-676-7763
City
Phoenix
Miami
Denver
Seattle
AccountBalance
197.54
255.93
863.39
353.76
Query: Which customers have balances greater than $200?
Access Query Screen (QBE)
Introduction to MIS
9
“AND” Conditions and Sorting
Sample Data
CID
28764
87535
44453
29587
Name
Adamz
James
Kolke
Smitz
Phone
602-999-2539
305-777-2235
303-888-8876
206-676-7763
City
Phoenix
Miami
Denver
Seattle
AccountBalance
197.54
255.93
863.39
353.76
Query: Which Denver customers have balances greater than $200?
Access Query Screen (QBE)
Introduction to MIS
10
SQL Introduction
CID
28764
87535
44453
29587
Name
Adamz
James
Kolke
Smitz
Phone
602-999-2539
305-777-2235
303-888-8876
206-676-7763
City
Phoenix
Miami
Denver
Seattle
AccountBalance
197.54
255.93
863.39
353.76
Query: Which customers have balances greater than $200?
SQL:
SELECT CID, Name, Phone, City, AccountBalance
FROM
Customers
WHERE AccountBalance > 200 ;
Query: Which Denver customers have balances greater than $200?
SQL:
SELECT CID, City, AccountBalancel
FROM
Customers
WHERE AccountBalance > 200 and City = “Denver”
ORDER BY Name ASC ;
Introduction to MIS
11
Useful WHERE Conditions
Comparisons
Numbers
Text
<, =, >, <>, BETWEEN
AccountBalance > 200
Name > “Jones”
Common
LIKE
Match all
Match one
Dates
Name LIKE “J*”
Name LIKE “?m*”
Odate between #8/15/95# and #8/31/95#
Missing data
NOT
City is NULL
Name is NOT NULL
Use with QBE or SQL
Introduction to MIS
12
SQL General Form
SELECT
FROM
JOIN
WHERE
GROUP BY
ORDER BY
Introduction to MIS
columns
tables
link columns
conditions
column
column (ASC | DESC)
13
Sum
Avg
Min
Max
Count
StDev
Var
Introduction to MIS
SQL
Computations
SELECT Count(C#), AVG(AccountBalance)
FROM
Customers ;
QBE
14
Groups or Subtotals
QBE
Sample Output
SQL
SELECT
FROM
GROUP BY
Introduction to MIS
City, AVG(AccountBalance)
Customers
City ;
City
AVG(AccountBalance)
Chicago
197.54
Denver
863.39
Miami
255.93
Phoenix
526.76
Seattle
353.76
15
Groups with Conditions
Query: What is the average account balance for customers from Denver?
Introduction to MIS
16
Multiple Tables
Customers
CID
12345
28764
29587
44453
87535
Name
Jones
Adams
Smitz
Kolke
James
Phone
312-555-1234
602-999-2539
206-656-7763
303-888-8876
305-777-2235
City
Chicago
Phoenix
Seattle
Denver
Miami
AccountBalance
$197.54
$526.76
$353.76
$863.39
$255.98
Salespeople
SID
225
452
554
663
887
Name DateHired
West
5/23/75
Zeke
8/15/94
Jabbar 7/15/91
Bird
9/12/93
Johnson 2/2/92
Phone
Commission
213-333-2345
5
213-343-5553
3
213-534-8876
4
213-225-3335
4
213-887-6635
4
Orders
OrderID CID
117
12345
125
87535
157
12345
169
29587
178
44453
188
29587
201
12345
211
44453
213
44453
215
87535
280
28764
SID
887
663
554
255
663
554
887
255
255
887
663
Odate
3/3/2004
4/4/2004
4/9/2004
5/5/2004
5/1/2004
5/8/2004
5/28/2004
6/9/2004
6/9/2004
6/9/2004
5/27/2004
Amount
$57.92
$123.54
$297.89
$89.93
$154.89
$325.46
$193.58
$201.39
$154.15
$563.27
$255.32
ItemsSold
Items
ItemID
1154
2254
3342
7653
8763
9987
Description
Corn Broom
Blue Jeans
Paper Towels--3 rolls
Laundry Detergent
Men's Boots
Candy Popcorn
Introduction to MIS
Price
$1.00
$12.00
$1.00
$2.00
$15.00
$0.50
OID
117
117
117
125
125
157
169
169
178
ItemID
1154
3342
7653
1154
8763
7653
3342
9987
2254
Quantity
2
1
4
4
3
2
1
5
1
17
Linking Tables
The Orders to ItemsSold relationship enforces referential integrity.
One Order can list many ItemsSold.
Introduction to MIS
18
Query Example
Which customers (CID) have placed
orders since June 1, 2004?
QBE
SQL
SELECT CID, ODate
FROM
Orders
WHERE Odate >= #6/1/2004# ;
CID
44453
44453
87535
28764
ODate
6/9/2004
6/9/2004
6/9/2004
6/27/2004
Introduction to MIS
Results
19
Query Example
What are the names of the customers who placed orders since June 1,
2004?
QBE
SQL
SELECT DISTINCT Name, Odate
FROM
Orders
INNER JOIN Customers ON
Orders.CID = Customers.CID
WHERE Odate >= #6/1/2004# ;
Name
Adamz
James
Kolke
Odate
6/27/2004
6/9/2004
6/9/2004
Introduction to MIS
Results
20
List the salespeople (sorted alphabetically) along
with the names of customers who placed orders
with that salesperson.
Query Example
SQL
SELECT DISTINCT Salespeople.Name,
Customers.Name
FROM
Salespeople INNER JOIN (Customers INNER JOIN Orders ON
Customers.CID=Orders.CID) ON Salespeople.SID = Orders.SID
ORDER BY Salespeople.Name ;
Results
SalesName Cust.Name
Bird
Adamz
Bird
James
Bird
Kolke
Jabbar
Jones
Jabbar
Smitz
Johnson
James
Johnson
Jones
West
Kolke
West
Smitz
Introduction to MIS
QBE
21
Aggregation Query
What is the total amount of orders placed from customers who live in
Miami?
QBE
Results
$2,418.84
SQL
SELECT SUM(Amount)
FROM
Orders
INNER JOIN Customers ON Orders.CID = Customers.CID
WHERE City = “Miami” ;
Introduction to MIS
22
Primary keys
One value per cell
Column depends on whole
key and nothing but the key.
Database Design
Customers
CID
11
22
33
44
name
Jones
Smith
James
Ricci
city
Chicago
Chicago
Chicago
Chicago
home
business
111-1111 222-2222
111-4567
111-2567 222-8976
fax
222-35534
service
876-3456
444-5353
333-8765
Phones(CID, phone_type, number)
Customers(CID, name, city)
CID
11
22
33
44
Introduction to MIS
name
Jones
Smith
James
Ricci
city
Chicago
Chicago
Chicago
Chicago
CID
11
11
11
11
22
22
33
44
phone_type
home
business
fax
service
home
service
home
fax
number
111-1111
222-2222
222-3534
876-3456
111-4587
444-5353
111-2567
333-8765
23
File: C05Vid.mdb
Database Design: Normalization
Introduction to MIS
24
Notation
Table
columns
Table
name
Customer (CustomerID, Phone, Name, Address, City, State, ZipCode)
Primary key is
underlined
CustomerID
1
2
3
4
5
6
7
8
9
10
Phone
502-666-7777
502-888-6464
502-777-7575
502-333-9494
502-474-4746
615-373-4746
615-888-4474
615-452-1162
502-222-4351
502-444-2512
Introduction to MIS
LastName
Johnson
Smith
Washington
Adams
Rabitz
Steinmetz
Lasater
Jones
Chavez
Rojo
FirstName
Martha
Jack
Elroy
Samuel
Victor
Susan
Les
Charlie
Juan
Maria
Address
125 Main Street
873 Elm Street
95 Easy Street
746 Brown Drive
645 White Avenue
15 Speedway Drive
67 S. Ray Drive
867 Lakeside Drive
673 Industry Blvd.
88 Main Street
City
Alvaton
Bowling Green
Smith's Grove
Alvaton
Bowling Green
Portland
Portland
Castalian Springs
Caneyville
Cave City
State
KY
KY
KY
KY
KY
TN
TN
TN
KY
KY
ZipCode
42122
42101
42171
42122
42102
37148
37148
37031
42721
42127
25