Database Systems Assignment 1

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

DATABASE SYSTEMS ASSIGNMENT 1

QUESTION 1

A University Library holds a large stock of books that are available for loan to borrowers. The library
requires a database to support the processing of these loans.

a) Examine the example records in the Forms (Figure 1) and the assumptions (Figure 2) shown below,
then draw an Entity Relationship diagram that includes the following:-

Entity types assigned with the attributes- (Indicate which attributes represent Primary keys).
Relationships between the entity types. (Resolve any many to many relationships)
Relationship cardinality and optionality constraints.

State the modelling notation you have used and state any necessary assumptions you make.
14 marks

b) Draft a set of Tables derived from your ER diagram populated with sample data from Form1 in Figure 1
shown below. You are required to indicate which columns are primary keys and which are foreign keys.
8 marks

c) Show with the aid of a diagram how your Tables are interlinked. (Related through columns) 3 marks

Figure 1: Three sample forms recording loans of copies of books over a period of time

Form 1
Title: The Joy of E-R Modelling Published_In 2013 ISBN: 939757

Author Id: AU505 Author Name : Moss


Author Id: ----- Author Name : ------

CopyNo C1034 Shelf Number C100 DateAcquired: 12-APR-16


Borrower Id Borrower Name Borrower Dept Loan Date Return Date
A12 Bloggs CIS 02-OCT-16 13-OCT-16
B34 Greenacre Business 13-OCT-16 27-OCT-16

Form 2
Title: Normalisation is Fun and Easy Published_In 2010 ISBN: 549950

Author Id AU1911 Author Name :Bollinger


Author Id AU505 Author Name : Moss

CopyNo C2399 Shelf Number: C101 DateAcquired: 22-APR-2011


Borrower Id Borrower Name Borrower Dept Loan Date Return Date

pg. 1 BY SHEPHERD RUNESU 0774479083/0719479083 [email protected]


B34 Greenacre Business 04-OCT-16 18-OCT-16
L67 Franks Leisure 22-OCT-16 29-OCT-16

Form 3
Title: Normalisation is Fun and Easy Published_In 2010 ISBN: 549950

Author Id AU1911 Author Name : Bollinger


Author Id AU505 Author Name : Moss

CopyNo C2400 Shelf Number: C101 DateAcquired: 25-JUN-2011


Borrower Id Borrower Name Borrower Dept Loan Date Return Date
A12 Bloggs CIS 04-OCT-16 25 OCT-16
L67 Franks Leisure 02-SEP-16 09-SEP-16

Figure 2: List of Assumptions

i. The library acquires one or many copies of books, these are physical copies of a particular
publication.
ii. A publication has a unique ISBN (an international code for all published works); a title and the date
it was published.
iii. Each copy has a unique copy number and has a particular shelf number to which it is located.
iv. A publication is always written by either one or two authors, and an author may write many
publications.
v. Only authors who have written at least one publication will be stored.
vi. A borrower may have more than one copy on loan at any time.
vii. A borrower may yet to take out a loan.
viii. Over time a copy may be out on loan many times or it may never be loaned out. ix. A loan is
made by a single borrower for one copy of a publication.

QUESTION 2

Refer to the following set of SQL statements and the sample tables for this question.

CREATE TABLE tickets(


ticketno NUMBER
,purchasedate DATE
,custid NUMBER
,fixtureid NUMBER
,seatid VARCHAR(5));

CREATE TABLE fixtures(


fixtureid NUMBER
,fixturedate DATE
,opposition VARCHAR(4));

CREATE TABLE customer(custid NUMBER


,custname VARCHAR(20)
,address VARCHAR(20));

pg. 2 BY SHEPHERD RUNESU 0774479083/0719479083 [email protected]


CREATE TABLE seats(
seatid VARCHAR(5)
,seatingarea VARCHAR(20)
,seat_type VARCHAR(20));

Sample tables

Table: seats
SEATID SEATINGAREA SEATTYPE
C11 West Stand Reserved
C12 West Stand
C13 West Stand
MM3 West Upper
MM4 West Upper Reserved
MM59 West Upper
H105 South Stand Family
H106 South Stand Family
H107 South Stand
G2 East Stand Away
G3 East Stand Away
K4 North Stand Disabled

Table: tickets
TICKETNO PURCHASEDATE CUSTID FIXTUREID SEATID
107823 13-Dec-2016 10032 8320 MM59
959235 13-Dec-2016 10032 8321 K4
309998 15-Dec-2016 13420 8322 MM3
306298 08-Mar-2017 13420 9767 MM3
736228 15-Oct-2016 13420 9770 C11
736229 15-Oct-2016 13420 8320 G2
736230 15-Oct-2016 17243 8320 C12
107922 13-Dec-2016 10035 8320 H105
107923 13-Dec-2016 10035 8320 H106

Table: fixtures
FIXTUREID FIXTUREDATE AWAYTEAM
8320 02-Jan-2017 CHEL
8321 23-Jan-2017 MANC
8322 18-Dec-2016 SUND
9767 15-Mar-2017 BORO
9770 16-Oct-2016 WATF
9889 05-Apr-2017 MANC

Table: customer
CUSTID CUSTNAME ADDRESS

pg. 3 BY SHEPHERD RUNESU 0774479083/0719479083 [email protected]


10032 R. Sayers Tess Ilkley Moor
17243 P. Smith ‘Homeblest’, Preston Capes
10035 V. Singh 23 Belle Vue St, Odiham
13420 P. Smith Dove Cottage, Stratford

a) Write SQL statements that populate the fixture table with the first 2 rows of data.
3 marks .
c) The CREATE TABLE statements are missing important constraints that could impact on the
integrity of data in the tables. . .

i) List three types of data integrity constraints that are absent in the script.

3 marks

ii) Write three SQL ALTER statements (one for each type of data integrity constraint)
that show how these data integrity constraints would be added to the script.

9 marks

d) Assume the script has been updated to include data integrity constraints. Why would an
error occur if an attempt is made to run the script again? What extra SQL code is required
to avoid this error occurring so that the script can run repeatedly?
5 marks

e) Write a query that counts the number of seats sold in each seatingarea for a fixture with
fixtureid = 8320.

The query should return :-

SEATINGAREA COUNT_OF_SEATS
West Stand 1
West Upper 1
South Stand 2
East Stand 1
5 marks

QUESTION 3

(a) A company uses the table below to record details of its projects. Each project is attached to a
department and runs for a certain duration (in months). The primary key for this table is
(projnbr, deptnbr):

PROJNBR DEPTNBR PROJNAME DEPTNAME DURATION


P01 D03 Web Portal HR Dept 10

pg. 4 BY SHEPHERD RUNESU 0774479083/0719479083 [email protected]


P01 D07 Web Portal Sales Dept 10
P02 D07 Data warehouse Sales Dept 7
P02 D03 Data warehouse HR Dept 7

(i) Give an example of an “Update Anomaly” that may occur in this table. 2 marks
(ii) Explain what is meant by “partial dependency” in a table. 1 mark
(iii) Identify any partial dependencies in the above table. 3 marks
(iv) Remove any partial dependencies from the above table by performing a normalisation
process and show skeletal designs of the resultant tables. 3 marks

(b) The following table keeps record of medical consultations conducted in a medical practice.
Each consultation takes place in a room and is conducted by a doctor on a patient. A patient
cannot have two consultations on the same day. Identify three candidate keys for this table.

PATIENTNBR CONSULTATIONDATE CONSULTATIONTIME DOCTORNBR ROOMNBR


P01 17-Aug-17 09:30 D01 R01
P01 20-Aug-17 14:00 D02 R02
P02 17-Aug-17 11:00 D01 R01
P03 17-Aug-17 11:00 D02 R02
P04 23-Aug-17 09:30 D01 R02

8 marks

(c) The following table has attributes A, B, C and D:

A B C D
a1 b1 c1 d1
a2 b1 c2 d1
a1 b2 c1 d1
a2 b2 c2 d1
a1 b3 c1 d2
a2 b3 c2 d2

(i) Explain what is meant by “functional dependency” in a table. 2 marks


(ii) (ii) Identify three functional dependencies from the above table. 6 marks

pg. 5 BY SHEPHERD RUNESU 0774479083/0719479083 [email protected]

You might also like