0% found this document useful (0 votes)
36 views28 pages

Sheets

The document outlines various exercises related to database systems, focusing on Entity-Relationship (ER) and Enhanced Entity-Relationship (EER) models. It includes scenarios for creating ER diagrams, defining relationships, and establishing business rules for different entities such as customers, employees, and students. Additionally, it covers logical database design, normalization, and SQL implementation for managing data effectively.

Uploaded by

rachele3728
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views28 pages

Sheets

The document outlines various exercises related to database systems, focusing on Entity-Relationship (ER) and Enhanced Entity-Relationship (EER) models. It includes scenarios for creating ER diagrams, defining relationships, and establishing business rules for different entities such as customers, employees, and students. Additionally, it covers logical database design, normalization, and SQL implementation for managing data effectively.

Uploaded by

rachele3728
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Database systems

Reference textbook: Modern Database Management 12th edition


Jeffrey A. Hoffer, V. Ramesh, Heikki Topi

Sheet 1 – ER Model
1- A cellular operator needs a database to keep track of its customers, their subscription plans, and the
handsets (mobile phones) that they are using. The E-R diagram in the following figure illustrates
the key entities of interest to the operator and the relationships between them. Based on the figure,
answer the following questions and explain the rationale for your response. For each question,
identify the element(s) in the E-R diagram that you used to determine your answer.

a. Can a customer have an unlimited number of plans? Yes


b. Can a customer exist without a plan? Yes
c. Is it possible to create a plan without knowing who the customer is? No
d. Does the operator want to limit the types of handsets that can be linked to a specific plan type? No
e. Is it possible to maintain data regarding a handset without connecting it to a plan? Yes
f. Can a handset be associated with multiple plans? No
g. Assume a handset type exists that can utilize multiple operating systems. Could this situation be
accommodated within the model included? No
h. Is the company able to track a manufacturer without maintaining information about its handsets? No
i. Can the same operating system be used on multiple handset types? Yes
j. There are two relationships between Customer and Plan. Explain how they differ.

The Is responsible for relationship indicates which customer is paying for the plan and the Belongs
relationship indicates which customer belongs to a plan but doesn’t necessarily pay for it.

k. Characterize the degree and the cardinalities of the relationship that connects Customer to itself. Explain its
meaning.

It’s a first degree one (optional)-to-many(optional). What that relationship means is that a customer may
have one or none family members and those family members can be that customers’ family or not.

l. Is it possible to link a handset to a specific customer in a plan with multiple customers? Yes
m. Can the company track a handset without identifying its operating system? No

Page 1
2- Consider the two E-R diagrams in the following figure, which represent a database of community
service agencies and volunteers in two different cities (A and B). For each of the following three
questions, place a check mark under City A, City B, or Can’t Tell for the choice that is the best
answer.

a- Can't tell , b- city A , c- Can't tell

3- 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, and No of
Years represents the number of years the student has engaged in this activity. A given student may
engage in more than one activity. Draw an ERD for this situation. What attribute or attributes did
you designate as the identifier for the STUDENT entity? Why?

4- The following is a grade report that is mailed to students at the end of each semester. Prepare an
ERD reflecting the data contained in the grade report. Assume that each course is taught by one
instructor. Explain what you chose for the identifier of each entity type on your ERD.

Page 2
5- The following figure represents a situation of students who attend and work in schools and who
also belong to certain clubs that are located in different schools. Study this diagram carefully to try
to discern what business rules are represented.

a. You will notice that cardinalities are not included on the Works For relationship. State a business rule for this
relationship and then represent this rule with the cardinalities that match your rule.

b. State a business rule that would make the Located In relationship redundant (i.e., where the school in which a
club is located can be surmised or derived in some way from other relationships).

c. Suppose a student could work for only a school that student attends but might not work. Would the Works For
relationship still be necessary, or could you represent whether a student works for the school she attends in some
other way (if so, how)?

Page 3
6- Draw an ERD for each of the following situations. (If you believe that you need to make additional
assumptions, clearly state them for each situation
a- A company has a number of employees. The attributes of EMPLOYEE include Employee ID
(identifier), Name, Address, and Birthdate. The company also has several projects. Attributes of
PROJECT include Project ID (identifier), Project Name, and Start Date. Each employee may be
assigned to one or more projects, or may not be assigned to a project. A project must have at least
one employee assigned and may have any number of employees assigned. An employee’s billing
rate may vary by project, and the company wishes to record the applicable billing rate (Billing
Rate) for each employee when assigned to a particular project.

Page 4
Do the attribute names in this description follow the guidelines for naming attributes? If not, suggest better
names.

Do you have any associative entities on your ERD? If so, what are the identifiers for those associative
entities?

Does your ERD allow a project to be created before it has any employees assigned to it? Explain. How
would you change your ERD if the Billing Rate could change in the middle of a project?

b- A laboratory has several chemists who work on one or more projects. Chemists also may use
certain kinds of equipment on each project. Attributes of CHEMIST include Employee ID
(identifier), Name, and Phone No. Attributes of PROJECT include Project ID (identifier) and Start
Date. Attributes of EQUIPMENT include Serial No and Cost. The organization wishes to record
Assign Date—that is, the date when a given equipment item was assigned to a particular chemist
working on a specified project. A chemist must be assigned to at least one project and one
equipment item. A given equipment item need not be assigned, and a given project need not be
assigned either a chemist or an equipment item. Provide good definitions for all of the relationships
in this situation.

Page 5
c- A college course may have one or more scheduled sections, or may not have a scheduled section.
Attributes of COURSE include Course ID, Course Name, and Units. Attributes of SECTION
include Section Number and Semester ID. Semester ID is composed of two parts: Semester and
Year. Section Number is an integer (such as 1 or 2) that distinguishes one section from another for
the same course but does not uniquely identify a section. How did you model SECTION? Why did
you choose this way versus alternative ways to model SECTION?

d- A hospital has a large number of registered physicians. Attributes of PHYSICIAN include


Physician ID (the identifier) and Specialty. Patients are admitted to the hospital by physicians.
Attributes of PATIENT include Patient ID (the identifier) and Patient 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 patients. Whenever a
patient is treated by a physician, the hospital wishes to record the details of the treatment
(Treatment Detail). Components of Treatment Detail include Date, Time, and Results. Did you
draw more than one relationship between physician and patient? Why or why not? Did you include
hospital as an entity type? Why or why not? Does your ERD allow for the same patient to be
admitted by different physicians over time? How would you include on the ERD the need to
represent the date on which a patient is admitted for each time they are admitted?

Page 6
Database systems
Reference textbook: Modern Database Management 12th edition
Jeffrey A. Hoffer, V. Ramesh, Heikki Topi

Sheet 2 – EER Model


Draw an EER diagram for the following problems using EER notation.

1- A nonprofit organization depends on a number of different types of persons for its successful
operation. The organization is interested in the following attributes for all of these persons: SSN,
Name, Address, City/ State/Zip, and Telephone. Three types of persons are of greatest interest:
employees, volunteers, and donors. Employees have only a Date Hired attribute, and volunteers
have only a Skill attribute. Donors have only a relationship (named Donates) with an Item entity
type. A donor must have donated one or more items, and an item may have no donors, or one or
more donors. There are persons other than employees, volunteers, and donors who are of interest to
the organization so that a person need not belong to any of these three groups. On the other hand, at
a given time a person may belong to two or more of these groups (e.g., employee and donor).
Add a subtype discriminator (named Paticipant Type) to the diagram you created

2- Wally Los Gatos and his partner Henry Chordate have formed a new limited partnership, Fin and
Finicky Security Consultants. Fin and Finicky consults with corporations to determine their

Page 7
security needs. You have been hired by Wally and Henry to design a database management system
to help them manage their business. Due to a recent increase in business, Fin and Finicky has
decided to automate its client tracking system. You and your team have done a preliminary
analysis and come up with the following set of entities, attributes, and business rules:

Consultant There are two types of consultants: business consultants and technical consultants.
Business consultants are contacted by a business in order to first determine security needs and provide
an estimate for the actual services to be performed. Technical consultants perform services according to
the specifications developed by the business consultants. Attributes of business consultant are the
following: Employee ID (identifier), Name, Address (which is composed of Street, City, State, and Zip
Code), Telephone, Date Of Birth, Age, Business Experience (which is composed of Number of Years,
Type of Business [or businesses], and Degrees Received). Attributes of technical consultant are the
following: Employee ID (identifier), Name, Address (which is composed of Street, City, State, and Zip
Code), Telephone, Date Of Birth, Age, Technical Skills, and Degrees Received.

Customer Customers are businesses that have asked for consulting services. Attributes of customer are
Customer ID (identifier), Company Name, Address (which is composed of Street, City, State, and Zip
Code), Contact Name, Contact Title, Contact Telephone, Business Type, and Number Of Employees.

Location Customers can have multiple locations. Attributes of location are Customer ID (identifier),
Location ID (which is unique only for each Customer ID), Address (which is composed of Street, City,
State, and Zip Code), Telephone, and Building Size.

Service A security service is performed for a customer at one or more locations. Before services are
performed, an estimate is prepared. Attributes of service are Service ID (identifier), Description, Cost,
Coverage, and Clearance Required.

Additional Business Rules In addition to the entities outlined previously, the following information
will need to be stored to tables and should be shown in the model. These may be entities, but they also
reflect a relationship between more than one entity: • Estimates, which have characteristics of Date,
Amount, Business Consultant, Services, and Customer • Services Performed, which have characteristics
of Date, Amount, Technical Consultant, Services, and Customer In order to construct the EER diagram,
you may assume the following: A customer can have many consultants providing many services. You
wish to track both actual services performed as well as services offered. Therefore, there should be two
relationships between customer, service, and consultant, one to show services performed and one to
show services offered as part of the estimate.

Page 8
3- An international school of technology has hired you to create a database management system to
assist in scheduling classes. After several interviews with the president, you have come up with the
following list of entities, attributes, and initial business rules:
- Room is identified by Building ID and Room No and also has a Capacity. A room can be either a
lab or a classroom. If it is a classroom, it has an additional attribute called Board Type.
- Media is identified by MType ID and has attributes of Media Type and Type Description. Note:
Here we are tracking type of media (such as a VCR, projector, etc.), not the individual piece of
equipment. Tracking of equipment is outside the scope of this project.
- Computer is identified by CType ID and has attributes Computer Type, Type Description, Disk
Capacity, and Processor Speed. Please note: As with Media Type, we are tracking only the type of
computer, not an individual computer. You can think of this as a class of computers (e.g., PIII
900MHZ).
- Instructor has identifier Emp ID and has attributes Name, Rank, and Office Phone.
- Timeslot has identifier TSIS and has attributes Day Of Week, Start Time, and End Time.
- Course has identifier Course ID and has attributes Course Description and Credits. Courses can
have one, none, or many prerequisites. Courses also have one or more sections.
- Section has identifier Section ID and attribute Enrollment Limit. After some further discussions,
you have come up with some additional business rules to help you create the initial design:
- An instructor teaches one, none, or many sections of a course in a given semester.
- An instructor specifies preferred time slots.
- Scheduling data are kept for each semester, uniquely identified by semester and year.
- A room can be scheduled for one section or no section during one time slot in a given semester of a
given year. However, one room can participate in many schedules, one schedule, or no schedules;
one time slot can participate in many schedules, one schedule, or no schedules; one section can

Page 9
participate in many schedules, one schedule, or no schedules. Hint: Can you associate this to
anything that you have seen before?
- A room can have one type of media, several types of media, or no media.
- Instructors are trained to use one, none, or many types of media.
- A lab has one or more computer types. However, a classroom does not have any computers.
- A room cannot be both a classroom and a lab. There also are no other room types to be
incorporated into the system.

Page 10
Database systems
Reference textbook: Modern Database Management 12th edition
Jeffrey A. Hoffer, V. Ramesh, Heikki Topi

Sheet 3 – Logical Database Design and the Relational Model

1- The following figure shows an EER diagram for a simplified credit card environment. There are
two types of card accounts: debit cards and credit cards. Credit card accounts accumulate charges
with merchants. Each charge is identified by the date and time of the charge as well as the primary
keys of merchant and credit card.
a. Develop a relational schema.
b. Show the functional dependencies.
c. Develop a set of 3NF relations using an enterprise key.

Page 11
2- The following Table contains sample data for parts and for vendors who supply those parts. In
discussing these data with users, we find that part numbers (but not descriptions) uniquely identify
parts and that vendor names uniquely identify vendors.

Develop a set of 3NF relations from PART SUPPLIER.

Page 12
3- The following figure shows an EER diagram for Vacation Property Rentals. This organization
rents preferred properties in several states. As shown in the figure, there are two basic types
of properties: beach properties and mountain properties.

a. Transform the EER diagram to a set of relations and develop a relational schema.
b. Diagram the functional dependencies and determine the normal form for each relation.
c. Convert all relations to third normal form, if necessary, and draw a revised relational schema.
d. Suggest an integrity constraint that would ensure that no property is rented twice during the
same time interval.

Page 13
To prevent overlaps, you would also need to use a combination of a check condition when
inserting new records. However, SQL does not allow direct overlapping checks in unique
constraints. Therefore, you'd typically enforce this through an application logic or trigger.

Page 14
Database systems
Reference textbook: Modern Database Management 12th edition
Jeffrey A. Hoffer, V. Ramesh, Heikki Topi

Sheet 4 – Implementation using SQL


1- Answer the following questions based on the figure of class scheduling 3NF rela ons

a- Write a database description for each of the relations shown using SQL DDL (shorten, abbreviate, or change
any data names, as needed for your SQL version). Assume the following attribute data types:
StudentID (integer, primary key)
StudentName (25 characters)
FacultyID (integer, primary key)
FacultyName (25 characters)
CourseID (8 characters, primary key)
CourseName (15 characters)
DateQualified (date)
SectionNo (integer, primary key)
Semester (7 characters)

Page 15
b- Use SQL to define the following view:

Page 16
c- How would you add an attribute, Class, to the Student table?

d- How would you remove the Registration table?

e- How would you change the FacultyName field from 25 characters to 40 characters?

f- List all students in alphabetical order by StudentName.

g- Which students have an ID number that is less than 50000?

h- What is the name of the faculty member whose ID is 4756?

i- What is the smallest section number used in the first semester of 2008?

j- How many students are enrolled in Section 2714 in the first semester of 2008?

k- Which faculty members have qualified to teach a course since 1993?

Page 17
l- Which students are enrolled in Database and Networking? (Hint: Use SectionNo for each class so you can
determine the answer from the Registration table by itself.)

m- Which instructors cannot teach both Syst Analysis and Syst Design?

n- List the courses available. Group them by course prefix. (ISM is the only prefix shown, but there are many
others throughout the university.)

o- Display the course ID and course name for all courses with an ISM prefix.

p- Display all courses for which Professor Berndt has been qualified.

q- Display the class roster, including student name, for all students enrolled in section 2714 of ISM 4212.

Page 18
r- How many students were enrolled in ISM 3113 during semester I-2008?

2- Answer the following questions about the following relations

Referenced from Tutorial 5: SQL By Chaofa Gao

Tables used in this note:


Sailors(sid: integer, sname: string, rating: integer, age: real);
Boats(bid: integer, bname: string, color: string);
Reserves(sid: integer, bid: integer, day: date).

Page 19
_______________________________________________________________________________

Page 20
Page 21
Page 22
-

Page 23
Database systems

Sheet 5 – B trees
1. Draw the B-tree of order 3 and order 4 created by inserting the following data
arriving in sequence. 92 24 6 7 11 8 22 4 5 16 19 20 78

Order = 3
Maximum number of keys = 2
Minimum number of keys = (ceil(3/2) – 1) = (2-1) = 1
Maximum number of children = 3
Minimum number of children = ceil(3/2) = 2

Page 24
Order = 4
Maximum number of keys = 3
Minimum number of keys = (ceil(4/2) – 1) = (2-1) = 1
Maximum number of children = 4
Minimum number of children = ceil(4/2) = 2

Page 25
2. Draw the B-tree of order 3 created by inserting data arriving in sequence from
the two sets shown below. Compare the two B-trees to determine whether the
order of data will create different B-tree.

Data 1: 89 78 8 19 20 33 56 44
Data 2: 44 56 33 20 19 8 78 89

Page 26
Conclusion: Different B-Trees are formed when using data arriving in different
sequences.

3. Using the B-tree of order 3 shown below, delete 63,90,41,60

Page 27
Page 28

You might also like