0% found this document useful (0 votes)
681 views

A01 Workbook 02 F

The document contains examples of conceptual data models for various business scenarios involving entities like students taking courses, employees working on projects, runners competing in marathons, etc. It describes the key entities, attributes, and relationships for each scenario and indicates cardinality and participation constraints for the relationships. Conceptual modeling forms the foundation for developing relational database schemas and SQL queries to represent and operate on the data.

Uploaded by

Andrea Detomas
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
681 views

A01 Workbook 02 F

The document contains examples of conceptual data models for various business scenarios involving entities like students taking courses, employees working on projects, runners competing in marathons, etc. It describes the key entities, attributes, and relationships for each scenario and indicates cardinality and participation constraints for the relationships. Conceptual modeling forms the foundation for developing relational database schemas and SQL queries to represent and operate on the data.

Uploaded by

Andrea Detomas
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 30

Table of Contents

I. Enterprise Modeling....................................................................................................2
II. Entities and relationships..........................................................................................4
III. Conceptual Modeling.............................................................................................5
Basic Queries................................................................................................................5
Working with less information........................................................................................7
Time-stamping...............................................................................................................8
Multiple relationships.....................................................................................................8
Unary Relationships......................................................................................................8
EER models.................................................................................................................10
Business rules.............................................................................................................12
IV Relational Schema...............................................................................................13
VI. SQL....................................................................................................................18
VII. Physical Design.................................................................................................29
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.

Process
The information system is intended to support the franchise management function of
New Age. It should provide the ability to identify prospective franchise owners,
record which franchises they acquire. The system should then record employees
assigned to each franchise and be able to print a report of employees by franchise.

Finally the system should record orders for products sent to each franchise. Orders
are unique to a single franchise (an owner cannot order for two or more franchises
on one order). Each order lists franchise information and the products being ordered
at that time. The order system does not do financial accounting and does not need
to keep track of fees or payments.

2 A bank has one or more branches. Each branch belongs to just one bank. Each
branch has one or more customers, but a customer is assigned to just one branch.
Each customer may own one or more accounts (accounts are owned by only one
customer). Customers submit transactions. Transactions are submitted by only one
customer but may be for more than one account.

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

Process
At the end of each run, the driver fills out a run ticket and enters it into the system.
The ticket identifies the driver and the truck and records time and mileage for the
run. A second input is a maintenance request. A driver will write up a maintenance
request for a vehicle that records problems that should be fixed. The system sends
2
these available to the appropriate maintenance worker. If the repair is a safety or
driveability problem, then the truck is scheduled for maintenance immediately.
Otherwise, the maintenance worker will make the repair during scheduled
maintenance.

4 Consider a simple course enrollment database for use by the Division of


Management in the CBA. The department offers several courses. At the beginning
of the semester the Division Director assigns an instructor to each course and
publishes a directory listing course and instructor office. By the 3rd week the
department produces a course roll for its own records. At the end of the semester
the instructor posts grades for each student in the course for that semester.

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

1 Assume a college environment


a. A student takes several courses; each course has many students

b. An instructor teaches several courses, but each course is taught by one


instructor.

c. Course has several sections; each section pertains to one course.

d. Course may have several textbooks; a given textbook is used in only one course.

3
II. Conceptual Modeling
(Include all attributes, relationships, and referential integrity indicators. Do not include
foreign keys.)

Basic Queries
1. A Girl Scout camp wants a database to keep track of which cabin each girl is
assigned to. Each girl is assigned to a single cabin with several other campers.
Each cabin has one counselor assigned to the cabin. The database should keep
track of camper name, camper home phone number, and the name of who to ask for
at that address. Each cabin needs cabin name, age group, and number of beds.
Each counselor has name, ID number and age.

2. Employees in the OU Physical Plant are assigned to a unique Department and work
on one or more Work Orders in a week. Draw an E-R diagram for a company
database to store EMPLOYEE-NAME, DEPARTMENT-NAME, DEPT-PHONE,
WORK-ORDER#, WORK-ORDER-DESCRIPTION, HOURS-WORKED-ON-WORK-
ORDER.

3. The director of a bowling tournament needs database to connect PLAYERS with


MATCHES. The database records PLAYER-NAME, PLAYER-PHONE, GAME-
TIME, LANE-NUMBER, and SCORE for each player. Draw an E-R diagram for this.
Include all attributes, and indicate cardinality and participation for all relationships.

4. The Marathoner, a monthly magazine, regularly reports the performance of


professional marathon runners. It has asked you to design a database to record the
details of all major marathons (e.g., Boston, London, and Paris). Professional
marathon runners compete in several races each year. A race may have thousands
of runners, but only about 200 or so are professional competitors, the ones that The
Marathoner tracks. For each race, the magazine records a runner's time and
finishing position, some personal details like name, gender, and age, and race
details like conditions, number of competitors, and date.

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

6. You are setting up a company that sells party favors (hats, T-shirts, sweat shirts,
etc.) to college groups. The PRODUCT inventory is identified by Item Number, Size,
and Color. Customers order products for different events customized by different
4
DESIGNS chosen from a design book. Each design can fit on all products.
Products are supplied by VENDORS and the company also needs to keep track of
different ORDERS that it has placed with each vendor noting the date the products,
the quantity ordered and the price paid for each item.

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

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

9. 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. A firm has a number of sales offices. Attributes include: office number and location.
Each sales office is assigned one or more employee. Attributes include: employee ID
and name. An employee must be assigned to only one sales office.
For each sales office, there is always one employee assigned to manage that office.
An employee may manage only the office to which he/she is assigned.
The firm lists property for sale. Attributes include: property ID and location.
Components of location include: address, city, state, and zip.
Each unit of property must be listed with only one sales office. An office may have
any number of properties listed (or no properties).
Each unit of property has one or more owner. Each owns some percentage of the
property. Attributes include: name, and ID. A person can own more than one
property.

5
11. 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.

12. Joes Hats sells hats at different charity events. Joe wants a system to keep track of
cash at each event. Every two hours each salesman turns in all the cash they have in
their cashbox. The system should keep track of date and time of the deposit, the
individual who turns the money in, the number of hats sold and the amount of money
turned in. Joe also has expenses for things like rental, food for workers and
advertising posters at each event. He keeps track of date of the expense, the payee,
the type of payment, the authorizing person and the amount paid. He wants a journal
system to track this.

13. The KM receiving office needs to track deliveries. The company orders products and
tracks order date, order number, product ID, product description, and quantity ordered.
Each order generates one or more shipments. Each shipment describes date, invoice
number, order number, product ID, description and quantity shipped. Once all of the
products have arrived the office issues a verification statement with date, order number
and invoice numbers to close the order.

14. The College of Business is interested in modeling its business processes. The
college is made up of several divisions. Each division has a name, division director,
and division phone number. Each division offers numerous courses. Only one
division offers a given course. Course number identifies each course. Other
information recorded for each course is the course name and the number of credits
that the course is worth. A course may be offered in several different sections. A
given section is an offering of exactly one course. Not all courses in the universitys
catalog are currently offered in a section, however. Each section has a unique
combination of course number, and section number to identify it (e.g., BIO2001 001).
Other information stored for each section includes the days offered (e.g., MWF, TR,
T, etc.), the time offered (e.g., 8:00-9:15, 2:00-3:15, etc.) and the location where the
class meets.

Information on students is also desired to be stored. Included in this information is


each students name and home address. The students phone number and status
are also recorded. Students are identified by a unique student number assigned to
each student. Students may enroll in one or more sections. Some students,
however, are not currently enrolled in any sections. Sections typically enroll
numerous students; however, it is possible for a section to be recorded that has no
students yet enrolled for it.

6
Some students serve as counselors for other students (e.g., incoming freshmen).
Counselors are volunteers that help other students with problems related with
student life. Not all students serve as counselors, but those that do often counsel
multiple students. Not all students have a counselor, but those that do are assigned
to only one counselor.

All students are also assigned one professor as an academic advisor. Most, though
not all, professors serve as advisors and typically advise numerous students.
Information to be stored on each professor includes their faculty ID (a unique
number assigned to all faculty), their name (consisting of first name and last name)
and their office phone number. Professors, of course, also teach the sections of
courses that are offered. Most professors teach one or more sections, but some
professors may be involved exclusively with research and perform no teaching role.
A given section may be taught by a single professor, or team taught by more than
one professor.

All professors are employed by the individual divisions. No professor is employed by


more than one division. Each division employs at least one professor. Each division
also has one professor that serves as the chairperson of that division. The next page
has been left blank for this model.

Time-stamping
15. The entity type STUDENT has the following attributes: StudentName, Address,
Phone, Age, Activity, and NoOfYears. Activity represents some campus-based student
activity, while NoOfYears represents the number of years the students has participated.
A given student may engage in more than one activity.

16. A stock brokerage sells stocks and the price constantly changes. Draw an E-R
diagram that takes into account the changing nature of stock prices.

Multiple relationships
17. 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.

7
Unary Relationships
18. 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.

19. Shawnee Manufacturing makes hydraulic pumps. They need to keep track of their
inventory. Pumps are manufactured on a Work Order which specifies the parts or
assemblies that are needed. The work order specifies date required, company
ordering the pump, pump serial number, and pump type. The system keeps track
of description, horsepower and name of each pump type. It also keeps track of
number, description, and number on hand for each part or assembly. Assemblies
are made up of other parts or assemblies in inventory.

8
EER models
(Extended ER models have keys, foreign keys, and constraints)

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

20. At a weekend retreat, an entity type PERSON has three subtypes: CAMPER,
BIKER, and RUNNER. Draw a separate EER diagram segment for each of the
following:
At a given time, a person must be exactly one of these.
A person may or may not be one of these subtypes. However, a person who is
one of these subtypes cannot simultaneously be one of the other subtypes.
A person may or may not be one of these subtypes. However, a person may be
any two (or even three) of these subtypes at the same time.
At any given time a person must be a member of one of these subtypes.

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

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.

Business rules
1. 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.

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

10
IV Relational Schema
1. Draw the relational schema for the following ER diagram.

Course_ Course_
Number Name

COURSE Is_prereq

Units

2. Draw the relational schema for the following ER diagram.

Section_
Course_ID Number

COURSE Has_ SECTION


scheduled

Semester_
Name Units ID

Semester Year

11
3. Draw the relational schema for the following ER diagram.

Billing_
Employee_ID
Rate Project_ ID

EMPLOYEE Is_assigned PROJECT

Name Address Birthdate Project Start_Date


_Name

4.

12
Draw the relational schema for the following ER diagram.

CONCERT
SEASON Opening _Date

Conductor_ID Conductor_
Name

Schedules

CONDUCTOR

Concert_
Number

CONCERT
Conducts
Concert_Date

Date_Last_
Performed

SOLOIST
Performs
Includes
Composer_
Name
Soloist_
Name Composition_
Composition Name
Soloist_ID _ID
Movement_
Number
COMPOSITION

Movement_
Name
Movement_ID

13
V. Normalization

The process I highly recommend you follow when completing a normalization problem is
as follows: 1) draw the data model, 2) convert 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.

1. Course and Section Problems. Normalize the following


a) Course (DEPT#, DEPARTMENT, COURSE#, CRS-TIME, FACULTY#, FAC-NAME)

b) Department (DEPT, PHONE, FACULTY#, FAC-NAME, MAJOR#, MAJOR TITLE)

c) Section (DEPT#, DEPARTMENT, INSTR#, INST-NAME, COURSE, TIME)

d) Course_Outcome (COURSE#, CRSE-NAME, STUDENT#, STU-NAME, GRADE)

e) Section (COURSE#, COURSE-NAME, INSTR#, INSTR-NAME, STUDENT#,


STU-NAME)

f) Create a database from a) through e) that is in 3NF.

2. Soccer Team Problems


a) Player (PLAYER-ID, NAME, TEAM, COACH)

b) Player (PLAYER-ID, PLAYER-NAME, PLAYER-ADDRESS, TEAM, COLOR,


COACH/ASST, COACH-PHONE)

c) Create a database from a) through b) that is in 3NF.

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

14
4. Normalize the following relation.

Owner Agent Property Price AgentPhone

5. The following table contains sample data for PART SUPPLIERS.

Part_No Description Vendor Name Address Unit_Cost


1234 Logic Chip Fast Chips Cupertino 10.00
Smart Chips Phoenix 8.00

5678 Memory Chip Fast Chips Cupertino 3.00


Quality Chips Austin 2.00
Smart Chips Phoenix 5.00

From interviews with the users, you have discovered that part number uniquely
identifies parts, and vendor name uniquely identifies vendors. Draw a set of 3NF
relations.

6. The following figure provides a sample report card from OU. Convert this user
view to a set of 3NF relations. Assume the following: An instructor has a unique location,
a student can have more than one major, and a course has a unique title.

University of Oklahoma
Grade Report
Fall Semester 199X
------------------------------------------------------------------------------------
Name: Emily Williams ID: 123456789
Campus Address: 208 Brooks Hall
Major: Information Systems
------------------------------------------------------------------------------------
Course Title Instructor Instructor Grade
ID Name Location
------------------------------------------------------------------------------------
MIS3113 Intro to MIS Nayar AH355 B
MIS2003 Prog. Concepts Price AH102 A
15
Normalization.
7. Convert the following to a conceptual model.

Branch Cust. Account Trans Trans. Cust. Name Trans. Acctunt Branch Custome
Name # # .# Date Amount Type Phone r Phone
Central 10010 000-001 3001 02/01/93 Jones, Sam 100.00 Checking 555-0100 555-0105
Central 10010 000-002 3055 02/01/93 Jones, Sam 25.00 Savings 555-0100 555-0105
Central 10010 000-021 3056 02/01/93 Jones, Sam -52.50 Checking 555-0100 555-0105
Central 10010 000-033 3057 02/02/93 Jones, Sam 1500.00 CD 555-0100 555-0105
Central 10010 000-003 3058 02/02/93 Jones, Sam 100.00 Safe 555-0100 555-0105
Deposit
Eastside 10020 000-009 3006 02/02/93 Abrams, Max 2599.00 Checking 555-0109 555-2204
Westlake 10020 000-009 3007 02/02/93 Abrams, Max -25.00 Checking 555-4232 555-2204
Eastside 10020 000-009 3008 02/03/93 Abrams, Max -10.00 Checking 555-0109 555-2204
Central 10030 000-006 3012 02/03/93 Cohen, 198.00 Checking 555-0100 555-0039
Esther
Central 10040 000-010 3010 02/03/93 Khan, Satya -824.00 Savings 555-0100 555-1001
Central 10040 000-010 3011 02/03/93 Khan, Satya -115.00 Savings 555-0100 555-1001
Westlake 10010 000-004 3081 02/03/93 Jones, Sam 190.25 Loan 555-4232 555-0105
Westlake 10050 000-018 3013 02/03/93 Brown, Judy 198.00 Checking 555-4232 555-9900
Central 10050 000-018 3014 02/03/93 Brown, Judy -165.99 Checking 555-0100 555-9900
Westlake 10050 000-005 3015 02/03/93 Brown, Judy 25.00 Loan 555-4232 555-9900
Eastside 10060 000-012 3044 02/04/93 Wales, Minnie -40.99 Checking 555-0109 555-0033
Eastside 10070 000-027 3017 02/04/93 Smith, Stan -886.00 Savings 555-0109 555-1250
Westlake 10070 000-027 3018 02/04/93 Smith, Stan 100.00 Savings 555-4232 555-1250

8. Normalize the following form. It is used by departments at OU to provide


information to the University Catalog
|----------------------------------------------------------------------------------------------------------------|
| Department: __________ Office Number: _________ Phone: ________
|
| Faculty Name Office Phone
|
| ________ _______ ________ |
| ________ _______ ________ |
| Classes ZAP# Course NumCourse Name Instructor
|
| ____ ________ ________________ ________ |
| ____ ________ ________________ ________ |

16
9. Normalize the following registration form. It is used to register children for
basketball teams. Players sign up individually for random assignment if they are new or
return to their old team if they are returning.
|----------------------------------------------------------------------------------------------------------------|
| Player Name: _______________ Address: __________ |
| Age Group: __________ Sex: ____ |
| Returning (Y/N) ______ Old Team: ________ Old Coach ______
|
| |
| Parents Name: __________ |
| Brothers/Sisters __________ Age __________ Sex _____ |
| __________ __________ _____ |
| |
| The following entries are for league use only
|
| League: ________ League Coordinator: ________ Team Assigned:
_______ |
| |

17
VI. SQL

1. Simple SQL (The SHARE table). This table represents stock prices for different
companies.

SHARE
SHRCODE SHRFIRM SHRPRICE SHRQTY SHRDIV SHRPE
AR Abyssinian Ruby 31.82 22010 1.32 13
BE Burmese 0.07 154713 0.01 3
BS Bolivian Sheep 12.75 231678 1.78 11
CS Canadian Sugar 52.78 4716 2.5 15
FC Freedonia Copper 27.5 10529 1.84 16
ILZ Indian Lead & 37.75 6390 3 12
NG Nigerian Geese 35 12323 1.68 10
PT Patagonian Tea 55.25 12635 2.5 10
ROF Royal Ostrich 33.75 1234923 3 6
SLG Sri Lankan Gold 50.37 32868 2.68 16

1. Draw a normalized ER model for this data:

2. Write the SQL statements necessary to create this database:

Write SQL to solve the following problems:

3. List a share's name and its code.

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.

10. Find the share with the minimum yield.

11. Find the total value of all shares with a PE ratio >10.

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

15. Find the total value of the portfolio.

16. List firm name and value in descending order of value.

17. List shares with a firm name containing 'Gold.'

18. Find shares with a code starting with 'B.'

19
2. More complex SQL (the DONOR tables)

DONOR
DONORNO DLNAME DFNAME DPHONE DSTATE DCITY
101 Abrams Louis 5559018 GA London
102 Aldinger Dmitry 5551521 GA Paris
103 Beckman Gulsen 5558247 WA Sao Paulo
104 Berdahl Samuel 5558149 WI Sydney
105 Borneman Joanna 5551888 MD Bombay
106 Brock Scott 5552142 AL London
107 Buyert Aylin 5559355 AK New York
108 Cetinsoy Girwan 5556346 AZ Rome
109 Chisholm John 5554482 MA Oslo
110 Crowder Anthony 5556513 NC Stockholm
111 Dishman Michelle 5553903 NC Helsinki
112 Duke Peter 5554939 FL Tokyo
113 Evans Ann 5554336 GA Singapore
114 Frawley Todd 5554785 MN Perth
115 Guo John 5556247 MN Moscow
116 Hammann John 5555369 ND Kabaul
117 Hays Cami 5551352 SD Lima
118 Herskowitz Thomas 5556872 MT London
119 Jefts Robert 5558103 ME Oslo

YEAR
YEAR YEARGOAL
1992 5000
1993 5000
1994 5500
1995 5000

20
GIFT
AMOUNT YEAR DONORNO
373 1992 101
543 1992 102
1185 1992 103
838 1992 109
582 1992 110
887 1992 111
666 1992 112
223 1992 114
82 1992 117
186 1992 119
939 1993 101
899 1993 102
1362 1993 103
667 1993 105
674 1993 108
297 1993 110
332 1993 111
558 1993 115
268 1993 116
772 1993 119
111 1994 102
5208 1994 103
332 1994 107
155 1994 108
499 1994 109
84 1994 110
882 1994 111
560 1994 113
835 1994 114
345 1994 116
1865 1995 103
60 1995 106
823 1995 110
812 1995 112
265 1995 116
657 1995 117
17 1995 118

21
1 Draw a normailzed ER model for this data:

2 Write the SQL statements necessary to create this database:

Write SQL to solve the following problems:


3 List the phone number of donor 112.

4 How many donors are there in the donor table?

5 How many people made donations in 1992?

6 What is the name of the person who made the largest donation in 1992?

7 What was the total amount donated in 1993?

8 List the donors who have made donations in every year.

9 List the donors who give twice the average.

10 List the total amount given by each person across all years, sort by donor name.

11 Report the total donations in 1994 by state.

12 In which years did the total donated exceed the goal for the year?

22
3. Multiple table queries (The SALE tables)
Icolor Dqty
Sqty Itype Dnum
Iname
Snum
SALE Consists ITEM DELIVERY
of

Made by

Manages Boss of
Spnum

Dname DEPT EMPLOYEE SUPPLIER


Works in
Enum
Dfloor Spname
Dphone Esalary
Ename

1. Create a relational schema for this diagram:

Perform the following SQL queries using your relational schema.

2. List the green items of type C

3. Find the name of green items sold by the recreation dept

4. Find the items not delivered to the books department

5. Find the departments that have never sold a Geo positioning system

6. Find the departments that sell at least four items

7. Find the items delivered by all suppliers (hint this is a universal qualifier problem)

8. Find the items not delivered by Nepalese Trading Company

9. Find the items sold by at least 2 departments

10. Find the items delivered for which there have been no sales

11. Find the name of the highest paid employee

12. Find the names of employees who make less than the average salary

23
13. List the number of employees for each department

14. Who earns the lowest salary

15. List the average salaries by department in descending order

24
4. Querying a Unary relationship (Departmental Assignments)

DEPT
DEPTNAME DEPTFLOOR DEPTPHONE EMPNO
Accounting 4 2003 5
Management 5 2001 1
Marketing 1 2002 2
Personnel 1 2005 9
Purchasing 4 2004 7

EMP
EMPNO EMPFNAME EMPSALARY DEPTNAME BOSSNO
1 Alice 75000 Management
2 Ned 45000 Marketing 1
3 Andrew 25000 Marketing 2
4 Clare 22000 Marketing 2
5 Todd 38000 Accounting 1
6 Nancy 22000 Accounting 5
7 Brier 43000 Purchasing 1
8 Sarah 56000 Purchasing 7
9 Sophie 35000 Personnel & PR 1

1. Draw a normalized ER model for this data:

2. Write the SQL statements necessary to create this database:

Write SQL to obtain the following information.


3. Find the departments where all employees earn less than their boss.

4. Find the names of all employees who are in the same department as their boss (as
an employee).

5. List the departments with an average salary greater than $25,000.

6. List the departments where the average salary of the employees of each boss is
greater than $25,000.

7. List the names and managers of the employees of the Marketing department who
have a salary greater than $25,000.

8. List the names of the employees who earn more than any employee in the Marketing
department.

25
5. Using an industrial database (Products Database)

C_
C_
SR_ STREET
FIRST
FIRST C_
SLSREP_ SR_ TOTAL_ LAST C_
CUSTOMER C_STATE
NUMB LAST COMMISSION CITY
_NUMBER
C_ ZIP_
SR_ CODE
ZIP_CODE SALES_REP Sells_to CUSTOMER
CREDIT_
SR_ LIMIT
STREET COMMISSION
_RATE BALANCE
SR_CITY SR_
STATE Places_Order

ITEM_
CLASS PART_ QUOTED
DESCRIPTION _PRICE
PART_
NUMBER ORDERDATE

UNITS_ PART ORDER_LINE ORDERS


ON_HAND
ORDER_
NUMBER
NUMBER_
UNIT_
WAREHOUSE ORDERED
PRICE
_NUMBER

1. Draw a normalized ER model for this data:

2. Write the SQL statements necessary to create this database:

Execute the following queries on the Premiere Products database. Print and turn in a
hard copy of the queries and results.

3. Find the part number and description of all parts.

4. List the complete sales rep table.

5. Find the names of all the customers who have a credit limit of at least $800.

6. Give the order numbers of those orders placed by customer 124 on 05-sep-00.

7. Give the part number, description, and on-hand value (units on hand * price) for
each part in item class "AP". (On-hand value is really units on hand * cost but we do
not have a cost column in the PART table.)

8. Find the number and name of all customers whose last name is "Nelson".
26
9. List all details about parts. The output should be sorted by part number within item
class.

10. Find out how many customers have a balance that exceeds their credit limit.

11. Find the total of the balances for all the customers represented by sales rep 12.

12. Find the number and name of all sales reps who represent at least one customer
with a credit limit of $1000.

13. List the totals of the balances for the customers of each sales rep.

14. List only the totals of the balances for sales reps with more than three customers.

15. List the number, name, and balance of each customer together with the number,
name, and commission rate of each customer's sales rep.

16. List the number and name of all sales reps who represent at least one customer who
lives in "Lansing".

17. List the number and name of all sales reps who do not represent any customers who
live in "Lansing".

18. Find the customer number and name of those customers who currently have an
order on file for an "Iron".

19. List the number and name of those sales reps together with the number and name of
any of their customers who have at least two orders on file.

20. List the number and description of those parts that are currently on order. (Make
sure each part is listed only once.)

21. Count the number of parts that are currently on order.

22. List the number and description of all parts that are currently on order by any
customer who is represented by the sales rep whose name is "William Smith ".

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

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.

28
3. Consider a company that has a national sales manager and 10 regional sales
people. Regional sales persons are located across the United States. Each sales
person has an average of 100 customers. These customers place an average of 5
orders a month. On average, customers buy 4 items per order. The company sells 500
different products. Order and Orderline data are maintained for a year. The data is
stored in relations that look like this:
SALESPERSON (Spnum, Spname, Region)
CUSTOMER (Cust#, Custname, Phone, Balance, Spnum)
ORDER (Order#, OrderDate, Cust#)
ORDERLINE (Order#, Product#, Quantity)
PRODUCT (Product#, Description, Unitprice, On_hand)

The national sales manager is very dissatisfied with the time it takes to get information
out of the computer system. He estimates the following usage patterns:
SALESPERSON:
queried 5 times per day
CUSTOMER:
queried 10 times per day individually
queried 50 times per day in combination with ORDER
queried 10 times per day in combination with SALESPERSON
ORDER:
queried 100 times per day individually
queried 200 times per day in combination with ORDERLINE
ORDERLINE:
queried 50 times per day individually
queried 100 times per day in combination with ORDER
queried 400 times per day in combination with PRODUCT
PRODUCT:
queried 200 times per day individually
queried 100 times per day in combination with ORDERLINE

You have been asked to do the following:


a) Draw a composite usage map.
b) List specific questions might you ask the sales manager to better understand the
physical design issues of greatest importance to this system.
c) Given your answers from parts A and B, what physical design recommendations
would you make to address the goal of improved retrieval time? Be specific!
d) The 10 salespeople are geographically dispersed across the U.S. They query the
system for information about their customers dozens of times each day. Further,
the national sales manager uses the system to generate sales reports and do
forecasting on a weekly basis. Finally, customers have access to the system to
query the expected delivery of merchandise on order; these queries average
about 50 per day and always involve the order, orderline, and product tables.
What recommendations would you make regarding physical distribution of the
database? Be specific.

29
Normalization

30

You might also like