You are on page 1of 10

NIT2212 DATABASE2

ASSIGNMENT
by Jiten Shrestha

VICTORIA UNIVERSITY
Sydney Campus
NIT2212 Database2 Assignment 1

Contents
Question 1.............................................................................................................................................2
ER Diagram........................................................................................................................................2
Assumptions:.....................................................................................................................................2
Relational Schema:............................................................................................................................2
Question 2.............................................................................................................................................2
ER Diagram........................................................................................................................................2
Assumptions:.....................................................................................................................................2
Relational Schema:............................................................................................................................2
Question 3.............................................................................................................................................2
Question 4.............................................................................................................................................3
Question 4.1......................................................................................................................................3
Question 4.2......................................................................................................................................3
Question 5.............................................................................................................................................4

Jiten Shrestha (s4581847) Page | 1


NIT2212 Database2 Assignment 1

Question 1
ER Diagram

Assumptions:
The following assumptions are made in the ER Diagram above:
 Each person has unique PersonID.
 Person should be either an author/writer or a reader.
 Book can have many editions.
 Book can have many readers and a reader can read many books.
 Book is written by only one author, but an author can write many books.

Relational Schema:
Table Field Type Description
PERSON PersonID INTEGER Primary Key

FirstName VARCHAR (20) Unique

LastName VARCHAR (20)

Age INTEGER (3)

Gender VARCHAR (10)

Address VARCHAR (30)

AUTHOR PersonID INTEGER Primary Key, Foreign Key

Jiten Shrestha (s4581847) Page | 2


NIT2212 Database2 Assignment 1

references Person(PersonID)

BirthPlace VARCHAR (30)

BestSeller VARCHAR (30) Unique

READER PersonID INTEGER Primary Key, Foreign Key


references Person(PersonID)

FavouriteAuthor VARCHAR (30)

Rating INTEGER

BOOK ISBN INTEGER Primary Key

Name VARCHAR (30)

Publisher VARCHAR (25)

BindingType VARCHAR (15)

PersonID INTEGER Foreign Key references


Author(PersonID)
EDITION EditionNumber INTEGER Primary Key

Price INTEGER

BindingType VARCHAR (10)

ISBN INTEGER Foreign Key references


Book(ISBN)

BOOKREADER ISBN INTEGER Primary Key, Foreign Key


references Book(ISBN)

Primary Key, Foreign Key


PersonID INTEGER references Reader(PersonID)

Jiten Shrestha (s4581847) Page | 3


NIT2212 Database2 Assignment 1

Question 2
ER Diagram

Assumptions:
The following assumptions are made in the ER Diagram above:
 A player has unique PlayerID.
 Player plays with one opponent at a time and vice versa.
 A player can play many matches and a match can have many players.

Relational Schema:
Table Field Type Description
PLAYER PlayerID INTEGER Primary Key

FirstName VARCHAR (20)

DateofBirth VARCHAR (20)

Country VARCHAR (15)

Ranking INTEGER

IdealPlayer VARCHAR (30) Unique

OpponentID INTEGER Primary Key

Jiten Shrestha (s4581847) Page | 4


NIT2212 Database2 Assignment 1

MATCH MatchID INTEGER Primary Key

Stadium VARCHAR (20)

Score INTEGER

PLAYER_MATCH PlayerID INTEGER Primary Key, Foreign Key


references Player(PlayerID)

MatchID INTEGER Primary Key, Foreign Key


references Match(MatchID)

OpponentID INTEGER Primary Key, Foreign Key


references Player(OpponentID)

Question 3
Given two relations R and S such that R contains two attributes A and B and S
contains only one attribute B. Implement the division operator R/S by using
other relational algebra operators (e.g., Cartesian product, projection, minus
etc.). In other words, the result obtained by your relational algebra expressions
must be the same as the result obtained by R/S.
Solution:
Considering relations R and S with their attributes and values as:

R S
A B
a 1
b 2
c 2
B
1
2

Cartesian product: R X S Union: R U S Intersection: R∩S

A B C A B
a 1 1 A B b 2
a 1 2 a 1 c 2
b 2 1 b 2
b 2 2 c 2
c 2 1
c 2 2
Difference: R-S Division: R /S

A
Jiten Shrestha (s4581847) b Page | 5
c
NIT2212 Database2 Assignment 1

A B
a 1

If T be the result of the required expression, the division of the given relations can be
shown in the basic relational algebraic term as:
T1←∏C(R)

T2←∏C((T1 × S) − R)

T ← T1 − T2

Which will be equal to:


R÷ S =
T1←∏C(R)

T2←∏C((T1 × S) − R)

T ← T1 − T2

Question 4
Suppose that a page can contain at most 4 data values and all data values are
integers. Using B+ trees of order 2, give examples of each of the following:
Question 4.1
a B+ tree with number of levels changed from 1 to 2 when the value 60 is inserted.
Show your structure before and after the insertion. (2 Marks).
Solution:
B+ tree with number of levels changed from 1 to 2 before the insertion is:

2 5 10 20

12 30 40

1 2

6 8

Then changes in B+ tree after insertion of the value 60 is:

Jiten Shrestha (s4581847) Page | 6


NIT2212 Database2 Assignment 1

2 5 10 20 40

40
20 12 16

1 2

6 8

Question 4.2
a B+ tree in which the deletion of the value 10 leads to a redistribution. Show
your structure before and after the deletion (2 Marks).
Solution:
B+ tree before the deletion is:

2 5 10 20 40

40
20 12 16

1 2

6 8

After deletion of the value 10 leads to the redistribution and the B+ tree becomes as:

3 6 12 20 40

40
20 12 16

1 2

Jiten Shrestha (s4581847) Page | 7


NIT2212 Database2 Assignment 1

6 8

Question 5
For each of the following transactions, determine if it is conflict serializable or
not? Show your working.
a.1) W1(X), R2(X), R1(Y), R3(X), W3(Y), R3(Y), R2(Y) (1 mark)
Solution:
Showing the above transactions in the table as:
T1 T2 T3
W1(X)
R2(X)
R1(Y)
R3(X)
W3(Y)
R3(Y)
R2(Y)

Which shows:
 Write and read conflict between T1 and T2 on X variable
 Read and write conflict between T1 and T3 on Y variable
 Write and read conflict between T3 and T2 on Y variable

Showing the above transactions in a cycle:

T1 T2

T3

The above graph shows an incomplete cycle, which means there is a conflict and
serializable.

Jiten Shrestha (s4581847) Page | 8


NIT2212 Database2 Assignment 1

b. 2) R1(X), W2(X), W2(Y), W3(Y), R1(Y)


Solution:
Showing the above transactions in the table as:
T1 T2 T3
R1(X)
W2(X)
W2(Y)
W3(Y)
R1(Y)

Which shows:
 Read and Write Conflict between T1 and T2 on X
 Write and read conflict between T2 and T3 on Y
Showing the above transactions in the graph as:

T1 T2

T3

The above graph shows an incomplete cycle, so the transaction is conflict and
serializable.

Jiten Shrestha (s4581847) Page | 9

You might also like