Workbook2 Database Exercises
Workbook2 Database Exercises
Fall 2001
Database
Table of Contents
I.
Enterprise Modeling................................................................................................................3
II.
III.
Conceptual Modeling...........................................................................................................6
Working from the bottom up...................................................................................................14
Unary Relationships.................................................................................................................15
EER models ............................................................................................................................16
Business rules..........................................................................................................................19
VI.
SQL....................................................................................................................................26
Simple SQL (The SHARE table).............................................................................................26
More complex SQL (the DONOR tables)...............................................................................29
Multiple table queries (The SALES tables).............................................................................34
Querying a Unary relationship.................................................................................................37
VII.
Physical Design.............................................................................................................39
I.
Enterprise Modeling
1. The NewAge Tax Preparation Company is a franchise operation. They sell one or more
franchises to owners who agree to use NewAge training programs and abide by the
companys policies. The companys primary sources of revenue are franchise fees and
products ordered by franchisees. The company operates as follows: owners enter into
franchise agreements, as a result they own at least one franchise location. Within each
location there are employees who provide a tax service to customers. In addition, franchise
locations order products from the company headquarters (for example, forms, brochures,
etc.). Draw the enterprise model.
2. The UR moving companys main source of revenue is that which is generated from its
drivers and trucks. The company is interested in keeping track of how many hours each
driver drives each truck. A driver may drive one or more trucks, and a truck may be driven by
one or more drivers. Because VT is a small venture, there are only three types of trucks in
their fleet. These are: 15-foot, 25-foot, and 30-foot. Each truck has a single maintenance
worker permanently assigned to perform maintenance on the truck, although a maintenance
worker may maintain more than one truck.
II.
4. An instructor teaches several courses, but each course is taught by one instructor.
6. Course may have several textbooks; a given textbook is used in only one course.
III.
Conceptual Modeling
9. A laboratory has several chemists who work on one or more projects. Chemists also may use
certain kinds of equipment on each project. Chemist information includes employee ID,
name, phone number. Project information includes ID and start date. Information maintained
about equipment includes serial number and cost. The organization wishes to record date
assigned when equipment is assigned to a chemist working on a project. A chemist must be
assigned to at least one project and one equipment item. A given piece of equipment need not
be assigned, and a given project need not be assigned either a chemist or equipment.
10. A hospital has a large number of registered physicians. Each physician has an ID and
specialty. Patients are admitted to the hospital by physicians. Patient information includes ID
and name. Any patient who is admitted must have exactly one admitting physician. A
physician may optionally admit any number of patients. Once admitted, a given patient must
be treated by at least one physician. A particular physician may treat any number of patients,
or may not treat any. Whenever a patient is treated by a physician, the hospital wishes to
record the details of the treatment such as date, time, and results.
11. Steve operates a cinema chain and has given you the following information:
I have many cinemas. Each cinema can have many theaters. Movies are shown throughout the
day starting at 11 am and finishing at 1 am. Each movie is given a 2-hour time slot. We never
show a movie in more than one theater at a time, but we do shifts movies among theaters
because seating capacity varies. I am interested in knowing how many people, classified by
adults and children, attend each showing of a movie. I vary ticket prices by movie and time slot.
12. At SalesRUs, invoices are written by sales reps. Each sales representative can write many
invoices, but each invoice is written by a single sales representative. An invoice is written for a
single customer, however each customer can have many invoices. An invoice can include many
detail lines which describe the products bought by the customer. Products are supplied by
different vendors.
13. A database for a local garage is needed. The database contains data items for a customer
account number, the customers name, the customers address, the customers work telephone
number, the customers home telephone number, date of work done, automobile make,
automobile model, description of work done, parts needed to complete the work, charge for
parts needed, and charge for labor performed. For warranty reasons, data must be maintained in
the database for at least ninety days; therefore, a customer may have several records in the
database at any particular time. Identical parts have only one cost, but different parts have
different costs (for example, all tires cost the same and all engines cost the same, but a tire and
an engine do not cost the same). A customer may have more than one car. Draw the ER
diagram to model these data relationships.
10
15. Mary Richards owns a house painting company. She has decided that she needs a better
record-keeping system that can be used to quickly retrieve information about her current and
former customers, such as their name and phone number. She already has detailed data about
the individual jobs that her company has done for these customers, such as the job number,
the beginning and end dates of the job, a brief description of the job, and the amount billed.
However, Mary would like to be able to easily relate this data to the jobs customer and to her
employees who worked on the job. Each job has a foreman and several other painters on it.
She also has information about all of her employees (their SSN, their name, their salary and
their phone number). Sometimes an employee will be a painter on one job and a foreman on
another. When a customer calls with a complaint about the work being done on their house
Mary needs to be able to determine who is or was the foreman on the job and who else
worked on the job.
Often times customers are referred by other customers, Mary thinks it would be a good idea
to store data about the referral sources. When a customer refers another customer Mary sends
$10 to the referring customer with a thank you note. Mary doesnt recognize multiple referral
sources for an individual customer and she has no interest in storing data on the self-referrals.
Of course a customer may refer many other customers to Mary.
11
16. Each semester, each student must be assigned an advisor who counsels students about degree
requirements and helps students register for class. Each student must register for class with
the help of an advisor, but if the assigned advisor is not available, the student may register
with any advisor. We must keep track of the students, assigned advisors, and name of advisor
with whom the student registered in the most recent semester.
12
Time-stamping
17. The entity type STUDENT has the following attributes: Student_Name, Address, Phone,
Age, Activity, and No_of_Years. Activity represents some campus-based student activity,
while No_of_Years represents the number of years the students has participated. A given
student may engage in more than one activity.
13
Cust.
#
10010
10010
10010
10010
10010
Account
#
000-001
000-002
000-021
000-033
000-003
Trans.
#
3001
3055
3056
3057
3058
Trans.
Date
02/01/93
02/01/93
02/01/93
02/02/93
02/02/93
Cust. Name
Eastside
Westlake
Eastside
Central
Central
Central
Westlake
Westlake
Central
Westlake
Eastside
10020
10020
10020
10030
10040
10040
10010
10050
10050
10050
10060
000-009
000-009
000-009
000-006
000-010
000-010
000-004
000-018
000-018
000-005
000-012
3006
3007
3008
3012
3010
3011
3081
3013
3014
3015
3044
02/02/93
02/02/93
02/03/93
02/03/93
02/03/93
02/03/93
02/03/93
02/03/93
02/03/93
02/03/93
02/04/93
Eastside
Westlake
10070
10070
000-027
000-027
3017
3018
02/04/93
02/04/93
Abrams, Max
Abrams, Max
Abrams, Max
Cohen, Esther
Khan, Satya
Khan, Satya
Jones, Sam
Brown, Judy
Brown, Judy
Brown, Judy
Wales,
Minnie
Smith, Stan
Smith, Stan
Jones, Sam
Jones, Sam
Jones, Sam
Jones, Sam
Jones, Sam
Trans.
Amount
100.00
25.00
-52.50
1500.00
100.00
Branch
Phone
555-0100
555-0100
555-0100
555-0100
555-0100
Customer
Phone
555-0105
555-0105
555-0105
555-0105
555-0105
2599.00
-25.00
-10.00
198.00
-824.00
-115.00
190.25
198.00
-165.99
25.00
-40.99
Account
Type
Checking
Savings
Checking
CD
Safe
Deposit
Checking
Checking
Checking
Checking
Savings
Savings
Loan
Checking
Checking
Loan
Checking
555-0109
555-4232
555-0109
555-0100
555-0100
555-0100
555-4232
555-4232
555-0100
555-4232
555-0109
555-2204
555-2204
555-2204
555-0039
555-1001
555-1001
555-0105
555-9900
555-9900
555-9900
555-0033
-886.00
100.00
Savings
Savings
555-0109
555-4232
555-1250
555-1250
14
Unary Relationships
19. Assume that at Pine Valley Furniture each product (described by product number,
description, and cost) is comprised of at least three components (described by component
number, description, and unit of measure) and components are used to make one or many
products. In addition, assume components are used to make other components, and that raw
materials are also considered components.
15
EER models (Extended ER models can have supertype/subtype relationships and business
rules)
20. A bank has three types of accounts: checking, savings, and loan. The attributes for each
account are as follows:
CHECKING: Account_No, Date_Opened, Balance, Service_Charge
SAVINGS: Account_No, Date_Opened, Balance, Interest_Rate
LOAN: Account_No, Date_Opened, Balance, Interest_Rate, Payment
Assume that each bank account must be a member of at least one of these subtypes.
16
21. A nonprofit organization depends on a number of different types of persons for its successful
operations. The organizations maintains the following information for these persons: SSN,
name, address, and phone. Three types of persons are of greatest interest: employees,
volunteers, and donors. For employees, the organization maintains a date hired, and for
volunteers, the organization maintains a list of skills. Donors donate items. They can donate
one or more items, and an item may be donated by more than one donor (i.e., a joint gift).
Persons may belong to more than one of these groups, or to none of them.
22. The American kennel association is trying to create a database of AKC registered dogs - prior
to their sale. They are preparing a prototype in Indiana. For each puppy, they want to retain
the puppys number (AKC registration code), and the puppys official name. They also need
to know if the puppy is show quality or pet quality. If show quality, then they want to retain
the date of last show and the place the puppy finished. If it is pet quality, they want to know
the defect and if the puppy likes children. Each puppy lives in a kennel. Each kennel has a
code, a name, and a location. Most kennels house quite a few puppies. The kennel
association also wants to keep track of the tricks each dog can do. A trick can have an id
code and a name. Some puppies cant do any tricks, while others can do many tricks. Its
also important to know when a puppy learned a certain trick.
17
23. A local Karate shop offers group and private lessons. Students (who have names, addresses,
phone numbers) can take either kind of lesson, or both. Group lessons are offered for
beginner, advanced, and intermediate levels. Private lessons are unique since each one has
only one student and its content depends on the student. Its also important for the Karate
shop to know how long a student has been a student.
18
Business rules
24. Consider the following rule: An employee may only be assigned to jobs for which he/she
has been certified.
a) draw the EER diagram segment
b) identify the constrained object and constraining object.
25. One university gymnastics team is interested in maintaining information about its current
schedule and meet performance. The team is made up of 10 gymnasts. Gymnast information
includes name, major, and hometown. The team competes in meets many times during the
season. Meet information includes date, location, and score. Meets consist of four events:
vault, beam, floor, and uneven bars. The final team score is an aggregation of event scores,
and event scores are aggregated individual gymnast scores. A meet can have one or more
opponents. The team faces each opponent only once during the season. A gymnast can
compete in all or some of the events, though the team is limited to 5 participants in each
event. Gymnasts can only compete in events for which they are trained.
19
IV
Relational Schema
Course_
Number
Course_
Name
COURSE
Is_prereq
Units
20
Section_
Number
Course_ID
COURSE
Name
Has_
scheduled
SECTION
Semester_
ID
Units
Semester
Year
21
Name
Employee_ID
Billing_
Rate
Project_ ID
EMPLOYEE
Is_assigned
PROJECT
Address
Birthdate
Project
_Name
Start_Date
22
Conductor_ID
Conductor_Name
CONCERT
SEASON
Opening_Date
CONDUCTOR
Schedules
Concert_Number
Conducts
CONCERT
Concert_Date
Date_Last_
performed
Performs
SOLOIST
Composer_Name
Includes
Composition_ID
Composition_
Name
Soloist_ID
Soloist_Name
COMPOSITION
Movement_
Number
Movement_ID
Movement_
Name
23
V.
Normalization
The process I highly recommend you follow when completing a normalization problem is as
follows: 1) draw the data model, 2) convert it to relational schema, 3) note the functional
dependencies, 4) normalize. Any problems at the end of Chapters 3 or 4 would also provide good
practice at this 4-step process.
30. Course and Section Problems
Normalize the following
a) Course (DEPT#, DEPARTMENT, COURSE#, CRS-TIME, FACULTY#, FAC-NAME)
24
32. INVOICE (Customer Number, Order Number, Product Number, Customer Name, Address,
Order Date, Order Quantity, Product Description, Unit Price)
Customers can place multiple orders and each order can be for a single or multiple
products.
Customers can order single or multiple quantities for each product.
Owner
Agent
Property
Price
AgentPhone
25
VI.
SQL
SHRFIRM
SHRPRICE SHRQTY SHRDIV
Abyssinian Ruby
31.82
22010
1.32
Burmese Elephant
0.07
154713
0.01
Bolivian Sheep
12.75
231678
1.78
Canadian Sugar
52.78
4716
2.5
Freedonia Copper
27.5
10529
1.84
Indian Lead & Zinc
37.75
6390
3
Nigerian Geese
35
12323
1.68
Patagonian Tea
55.25
12635
2.5
Royal Ostrich
33.75
1234923
3
Sri Lankan Gold
50.37
32868
2.68
SHRPE
13
3
11
15
16
12
10
10
6
16
26
4. List full details for all shares with a price less than one dollar.
5. List the name and price of all shares with a price of at least $10.
6. List the name, share price, share holding, and total value of shares held (this is number of
shares times share price).
7. List the name of all shares with a yield exceeding 5 percent (yield is equal to the dividend
divided by the price).
8. Report the total dividend payment of Patagonian Tea (the total dividend payment is the
dividend times quantity).
9. Find all shares where the price is less than 20 times the dividend.
11. Find the total value of all shares with a PE ratio >10.
27
12. Find the share with the maximum total dividend payment.
13. Find the value of the holdings in Abyssinian Ruby and Sri Lankan Gold.
14. Find the yield of all firms except Bolivian Tea and Canadian Sugar.
28
DLNAME
Abrams
Aldinger
Beckman
Berdahl
Borneman
Brock
Buyert
Cetinsoy
Chisholm
Crowder
Dishman
Duke
Evans
Frawley
Guo
Hammann
Hays
Herskowitz
Jefts
DFNAME
Louis
Dmitry
Gulsen
Samuel
Joanna
Scott
Aylin
Girwan
John
Anthony
Michelle
Peter
Ann
Todd
John
John
Cami
Thomas
Robert
DPHONE
5559018
5551521
5558247
5558149
5551888
5552142
5559355
5556346
5554482
5556513
5553903
5554939
5554336
5554785
5556247
5555369
5551352
5556872
5558103
DSTATE
GA
GA
WA
WI
MD
AL
AK
AZ
MA
NC
NC
FL
GA
MN
MN
ND
SD
MT
ME
DCITY
London
Paris
Sao Paulo
Sydney
Bombay
London
New York
Rome
Oslo
Stockholm
Helsinki
Tokyo
Singapore
Perth
Moscow
Kabaul
Lima
London
Oslo
YEAR
YEAR
YEARGOAL
1992
5000
1993
5000
1994
5500
1995
5000
29
GIFT
AMOUNT
373
543
1185
838
582
887
666
223
82
186
939
899
1362
667
674
297
332
558
268
772
111
5208
332
155
499
84
882
560
835
345
1865
60
823
812
265
657
17
YEAR
DONORNO
1992
101
1992
102
1992
103
1992
109
1992
110
1992
111
1992
112
1992
114
1992
117
1992
119
1993
101
1993
102
1993
103
1993
105
1993
108
1993
110
1993
111
1993
115
1993
116
1993
119
1994
102
1994
103
1994
107
1994
108
1994
109
1994
110
1994
111
1994
113
1994
114
1994
116
1995
103
1995
106
1995
110
1995
112
1995
116
1995
117
1995
118
30
31
4. What is the name of the person who made the largest donation in 1992?
8. List the total amount given by each person across all years, sort by donor name.
10. In which years did the total donated exceed the goal for the year?
33
Icolor
Iname
Dnum
Itype
Dqty
Snum
SALE
Consists
of
DELIVERY
ITEM
Made by
Boss of
Manages
Dname
Dfloor
DEPT
EMPLOYEE
SUPPLIER
Works in
Dphone
Spnum
Enum
Esalary
Ename
Spname
34
5. Find the departments that have never sold a Geo positioning system
9. Find the items delivered for which there have been no sales
11. Find the names of employees who make less than the average salary
36
BOSSNO
1
2
2
1
5
1
7
1
37
2. Find the names of all employees who are in the same department as their boss (as an
employee).
4. List the departments where the average salary of the employees of each boss is greater than
$25,000.
5. List the names and managers of the employees of the Marketing department who have a
salary greater than $25,000.
6. List the names of the employees who earn more than any employee in the Marketing
department.
38
VII.
Physical Design
1. You are working for a large global corporation that sells personalized gift baskets. There is a
data communications network that links a computer at corporate headquarters (in London)
with a computer at each retail outlet. There are 50 stores with an average of 75 employees
per store. There are 12 departments in each store.
Assume:
A daily schedule of employees hours is kept for 7 months.
The store manager for each store updates the employee work schedule about 5 times an hour.
The headquarters handles all payroll checks.
Corporate HQ handles all information about store managers and store managers handle all
information about their employees.
The relations look like:
STORE(Store_Id, Region, Manager_Id, Square_Feet)
EMPLOYEE(Emp_Id, Store_Id, Name, Address)
DEPARTMENT(Dept#, Store_ID, Manager_Id, Sales_Goal)
SCHEDULE(Dept#, Emp_Id, Date, hours)
Draw a composite usage map and make recommendations about denormalizing, partitioning, and
indexing.
39
2. A medical clinic has the following relational schema for its data.
PERSON(person_ID, name, address, DOB)
PATIENT(PA_person_ID, Contact)
PHYSICIAN(PH_person_ID, specialty)
PERFORMANCE(PA_person_ID, PH_person_ID, Treatment#, Treatment_date,
Treatment_time)
CONSUMPTION(PA_person_ID, Item#, Date, Quantity)
ITEM(Item#, Description)
Draw a composite usage map and make recommendations about denormalizing, partitioning, and
indexing.
40