Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

cs3200, Fall 2019, Section 1

Problem Set 2
Due: Tues 15 October at noon.

Learning Goals
By the end of this assignment you should have:

1. practice creating an ER diagram from written requirements;

2. understand how to translate a conceptual ER diagram into a logical relational schema; and
3. hone your understanding of SQL constraints.

What to Hand in and Working with Partner


A pdf file named PS2.pdf containing your ER Design. This may not be hand drawn. You can use any
drawing tool you’d like, but please follow the diagramming conventions from the course slides. The course
web page contains a Powerpoint and Keynote version of the diagram used in the second question that you
are welcome to use as a template.
Also hand in a file named PS2.sql. Your file must be executable using the command psql -f PS2.sql, from
a Unix-based prompt, or within the psql command line with the command \i PS2.sql. Your submission
file must contain comments that explain each table. This will facilitate grading and partial credit. If you use
SQL statements not taught in class (on course slides), explain why and state whether these are necessary (is
there a correct design that does not use them?) Remember, use two dashes (–) to add comments in SQL.
You may work by yourself or with a partner. If with a partner, you must both submit on blackboard
the identical file and the file must include both of your names, student numbers at the top (in an SQL
comment). Please also include the statement: “We both fully understand all queries and solutions that we
are submitting.”

1 ER Design
A car rental service provides cars for rent to customers for a period of time. Cars are kept at rental stations
which are situated at fixed locations.

System Functional Requirements

Customers provide their name, age and email to register into the system and are given a unique id. Once
registered, a customer can make reservations for a car from a particular location giving both the rental date
and time and the return date and time. Each reservation has a unique id and a status. Before the rental
date and time, the value of the status is confirmed, once the customer picks up a car, the status is changed
to on-going. If the customer does not pick up the car or cancels the reservation before the rental data, the
status is changed to cancelled. After the car is returned the status is changed to complete. Each reservation
(that is not cancelled) involves exactly one car which has a make, model, and a unique license number. Every
rental station has a unique code, along with a name and a location. Once a reservation is complete an invoice
is generated and sent to the customer. The invoice has a number (which together with the reservation id is

1
unique), a date, an amount, and a status (unpaid/paid). If the invoice is not paid within a certain period a
new invoice for the same reservation, but with a new number, is generated (with an amount that includes
10% penalty).
Design an ER diagram for the car rental service using the (min, max) cardinality constraints and dia-
gramming conventions used in the course slides. The design should be for an operational database to help
the company run its business. For accounting, the company needs to keep a record of all past and current
reservations and invoices. Consider what should be modeled as data values (and therefore is not in the ER
diagram) and what should be part of the schema. The data can change as new reservations are made and
time passes, but your schema should be fixed and able to represent the data mentioned. You may attach a
written explanation of your design decisions and how they capture the information above.

ER2Relations
Create a relational schema that represents the information in the ER diagram below. Write all the create table
statements and constraints needed to enforce the constraints in the ER diagram. If any of the constraints
can not be expressed in SQL using your design or a different design with primary keys, foreign keys, unique
constraints or non-null constraints, explain why. For such constraints, write an SQL query that returns
’True’ if the constraint is satisfied on the database, and ’False’ otherwise.
Your solution must run in postgres.

(0,N) Part
Composition
Num
Name Desc Quantity
Number Part
Loc (0,M)
Address Customer
CredLimit Code (0,M)
Discount (0,N) Quantity

Product
Composition
Places Quantity CompletedDate
Num EstComp
(0,N) ProdLine
Desc
(1,1) Num
Date Name
(1,N) (0,N) (1,1)
Order Contains Product ReOrder ProductionOrder
(0,M)
Num QonHand
(0,N) (0,N) UnitPrice
(1,N) (1,1)
ReorderPt ReorderQ
Order
Payment Billed Routing
Manages
(0,N)
(1,1) (1,1) (1,1)
Num
Invoice (0,N)
Payment
Desc (0,N)
(1,1)
Operation PerformedAt WorkCenter
Setup
Amount Date Amount Date Number
StdOp

Figure 1: ER Diagram

You might also like