Sunteți pe pagina 1din 15

No: XXXX

THE CITY UNIVERSITY





Advanced Databases

IN3001

(Model Answer)




Date and year Time of exam



Please read the instructions carefully

Info on how many questions should be answered will be here





Calculators are allowed, except programmable ones
















External Examiner: XXXXX Examiner: XXXXX


Question 1

(a) Consider a relational database that maintains information about online booking of
medical appointments including patients names and addresses, doctors names and
addresses, patients symptoms, date/time of appointments, patients history, and
description of the consultation.

For each transaction control property, explain the property and give an example of a
problem that might occur with the medical appointment database above if the property is
not supported (40 %)

Model Answer:

Atomicity: is the property related to the fact that either all the operations in a transaction
are reflected properly in the database, or none of them are.

Example: An appointment slot is allocated to a patient, but the patients symptoms are
not registered in the booking. (10%)

Consistency: is the property related to the fact that the execution of a transaction must
preserve the consistency of the database.

Example: The patient is allocated an appointment in the correct date and time, but with a
wrong doctor. (10%)

Isolation: is the property related to the fact that concurrent transactions are executed
independently of one another.

Example: Two patients are allocated the same appointment with the same doctor. (10%)

Durability: is the property related to the fact that the effects of a successfully completed
transaction are stored in the database and not lost because of failure.

Example: The customer receives a confirmation from the system about his appointment,
but there is a crash in the system and the effect of the transaction is not recorded on the
database. (10 %)


b) Consider the following Entity-Relationship diagram for an estate agent. Write a
Document Type Definition (DTD) to represent a scheme for the structure of the
information described in the Entity-Relationship diagram. Instantiate this DTD and create
an XML document conforming to the DTD. Make sure to use both elements and
attributes for modelling the structure.

(30% for the DTD)
(30% for the XML document)




























Model Answer


DTD (StateAgent.dtd)

<!ELEMENT StateAgent(Agent+, Property+, Person+, Contract+)>
<!ATTLIST StateAgent
Name CDATA #REQUIRED>
<!ELEMENT Agent EMPTY>
<!ATTLIST Agent
Agent# ID #REQUIRED
Name CDATA #REQUIRED
Address CDATA #REQUIRED
Sex CDATA #REQUIRED>

<!ELEMENT Property (House*, Flat*)>
<!ATTLIST Property
Agent
Person
Property
Flat
House
responsible
contract
Is-A
Agent
# Name
Address
Sex
SS
N
Address
Name
Phone
Credit
Date_contr
Prop#
BedNum
m
ZipC
Addres
s
Lease
Garden_size
Floor
1
N
N
N
Prop# ID #REQUIRED
Address CDATA #REQUIRED
BedNum CDATA #REQUIRED
ZipC CDATA #REQUIRED
Lease CDATA #REQUIRED
Agent# IDREF #REQUIRED>
<!ELEMENT House EMPTY>
<!ATTLIST House
GardenSize CDATA #REQUIRED>
<!ELEMENT Flat EMPTY>
<!ATTLIST Flat
Floor CDATA #REQUIRED>

<!ELEMENT Person EMPTY>
<!ATTLIST Person
SSN ID #REQUIRED
Name CDATA #REQUIRED
Address CDATA #REQUIRED
Phone CDATA #REQUIRED
Credit CDATA #REQUIRED>

<!ELEMENT Contract EMPTY>
<!ATTLIST Contract
SSN IDREF #REQUIRED
Prop# IDREF #REQUIRED
Date_contr CDATA #REQUIRED>



XML (SateAgency.xml)

<?xml version=1.0?>
<!DOCTYPE Department System Department.dtd>
<Department
Name=FindYourHouse>
<Agent
Agent# = AG1
Name = Anthony
Address = Wide Road, 345
Sex = M>
</Agent>
<Agent
Agent# = AG2
Name = Mary
Address = Narrow Road, 123
Sex = F>
</Agent>
<Property
Prop# = PR1
Address = Blue Street, 222
BedNum = 1
ZipC = NS34RF
Lease = 125
Agent# = AG1>
<Flat
Floor = second>
</Flat>
</Property>
<Property
Prop# = PR2
Address = Green Street, 333
BedNum = 3
ZipC = SN25PK
Lease = 999
Agent# = AG1>
<Flat
Floor = third>
</Flat>
</Property>
<Property
Prop# = PR3
Address = Red Road, 555
BedNum = 5
ZipC = NW6 PKX
Lease = Freehold
Agent# = AG2>
<House
GardenSize = 200 square feet>
</Hoiuse>
</Property>
<Person
SSN = CA222222
Name = John Taylor
Address = White Avenue, 444
Phone = 020 7444444444
Credit = 1000>
</Person>
<Person
SSN = CA3333333
Name = Tracy Black
Address = Green Crescent, 555
Phone = 020 7555555555
Credit = 10,000>
</Person>
<Contract
SSN = CA3333333
Prop# = PR3
Date_contract = 20/10/2006 >
</Contract>
</StateAgent>



Question 2

a) Consider the following requirements for the Department of Computing database.

The department of Computing is composed of several sections. Each section is
identified by a number, has a name, a section head and a research area. Each
section head is the head of only one section. The department has academics that
teach courses. Each academic has a rank and teaches many courses. Each course
is identified by a code, has a title and can be taught by many academics. All
academics and section heads are departmental staff. Each departmental staff
belongs to exactly one section, has a number, name, and salary. A section can
have many members of the departmental staff. Another type of departmental staff
is the teaching assistant. The teaching assistants assist the academics in the
teaching of courses. One teaching assistant can assist many academics in the
teaching of courses. However, for each academic teaching a course there is the
help of at most one teaching assistant. There are also some academics that teach
courses without the help of teaching assistants.

Model the above database description in John Hughes OO schema format (40 %)


Model Answer:

(a) John Hughes (40%)

class Section

properties

secode: Integer;
name:String;
area:AreaList;

managed_by: Head inverse is Head.ismanaged;
contains: Set(Depart_Staff) inverse is Depart_Staff.belongs_to;

operations

create()

end Section.

class Depart_Staff

properties

deps#: Integer;
name:String;
salary:Float;

belongs_to: Section inverse is Section.contains;

operations

create()

end Depart_Staff.

class Head

inherit Depart_Staff

properties
manages: Section inverse is Section.managed_by;

operations

create()

end Head.

class Teaching_Assistant

inherit Depart_Staff

properties
assists: Set(Academics) inverse is Academics.is_assisted_by;

operations

create()

end Teaching_Assistant.


class Academics

inherit Depart_Staff

properties
rank: string;
is_assisted_by: Teaching_Assistant inverse is Teaching_Assistant.assists;
teach: Set(Course) inverse is Course:is_taught_by;

operations

create()

end Academics.


class Course
properties
code: string;
title: string;
is_taught_by: Set(Academics) inverse is Academics:teaches;

operations

create()

end Course.




(b) Explain the 2 phase locking protocol used for distributed database systems. (30%)

Model Answer

The 2PL protocol is used to allow concurrency control of transactions in both centralised
and distributed database systems. In the case of distributed databases, each site has a lock
manager that is responsible for all local locks. If the data is not replicated, the protocol is
executed in each site as in the case of a centralised database in two phases. The first
phase is called growing phase and the second phase is called shrinking phase. In the
growing phase, a transaction can request all the necessary locks. In the shrinking phase a
transaction cannot request any lock and should release the locks. Once the transaction has
released a lock, this transaction cannot request any other lock to any data item. If the data
is replicated, then any copy of the data can be used for reading. However, in the case of
updating the data, it is necessary to issue a write lock to all replicated copies following
the growing and shrinking phases characteristics.

c) Describe the recovery scheme that can be used to recover a database in case of failure
when the database makes use of a log file and the checkpoint technique. (30 %)

Model Answer

Recovery Scheme:

Examine the log file to find the most recent transaction T that started before the most
recent checkpoint has occurred;
Identify all transactions Ti that started after transaction T and create a set (T_Set)
with these transactions Ti and transaction T;
For all Ti in T_Set that does not have a <Ti commit> record in the log file, execute
undo (Ti);
For all Ti in T_Set that has <Ti commit> in the log file, execute redo(Ti);
Undo operations to all transactions Tj that started before T and has not committed
(are still active) during time of failure.




Question 3:

Consider the ORDBS model given below.

Create rowtype PersonType
(Name char(30) not null,
Address char(50),
Age char(3));

Create rowtype HospitalType
(Name char(30) not null,
Head ref(PersonType),
Address char(50),
City char(10));

Create rowtype OperationType
(OpName OpListType,
Surgeon ref(PersonType),
Patient ref(PersonType),
Nurses setof(PersonType),
Hospital ref(HospitalType),
Time char(5),
Date char(10));

Create rowtype OpListType
(Type char(20),
AppDuration char(10));

Create table Nurses of type PersonType;

Create table Surgeon of type PersonType;

Create table Patient of type PersonType;

Create table Operation of type OperationType;

Create table Hospital of type HospitalType;

Create table Head of type PersonType;

a) Specify the queries below in SQL-3 format.

i) List the names of any surgeons that have participated in an operation performed
on the 25/10/2002 at 12:00 pm. (10%)
ii) List the addresses of any hospitals where operations of type orthopaedics have
been executed (15%)
iii) List the name of the head of the hospital located in London where Dr Peter Brown
has performed an eyesight operation
(15%)

Model Answer:

i) List the names of any surgeons that have participated in an operation performed
on the 25/10/2002 at 12:00 pm. (10%)

SELECT Surgeon->name
FROM Operation
WHERE Operation.time=12:00 and
Operation.date=25/10/2002


ii) List the addresses of any hospitals where operationsof type orthopaedics have
been executed (15%)

SELECT Hospital->address
FROM Operation
WHERE OpName..type=orthoapedics

iii) List the name of the head of the hospital located in London where Dr Peter Brown
has performed an eyesight operation
(15%)
SELECT Hospital->Head->Name
FROM Operation
WHERE OpName..type=eyesight and
Surgeon->Name = Dr Peter Brown and
Hospital->City = London

b) Give a relational schema representation of this database, specifying the relations,
attributes, primary and foreign keys. (30%)

Model Answer:

Person(P#, name, address, age)
Surgeon(P#)
Nurse(P#)
Patient(P#)
Head(P#)
Hospital(Hospt#, name, adress, city, head#)
Operation(op#, type, duration, time, date, surgeon#, patient#, hospital#)
Nurse_Participation(nurse#, op#)


c) List, explain, and evaluate two different techniques used to distribute data when
dealing with distributed database systems. (30 %)

Model Answer:

(or any other alternative choice)

Data fragmentation is a technique used to distribute the data around the sites when
dealing with distributed database systems. It allows efficient data distribution and
processing. The data can be fragmented horizontally or vertically. In a horizontal
fragmentation a relation R is divided into many fragments Ri with the same schema R. In
a vertical fragmentation a relation R is divided into many fragments Ri which represent
projections of R.

Example:

Employee
EmpNum Name DeptName Salary Tax
1 Robert Production 3.7 1.2
2 Greg Administration 3.5 1.1
3 Anne Production 5.3 2.1
4 Charles Marketing 3.5 1.1
5 Alfred Administration 3.7 1.2
6 Paolo Planning 8.3 3.5
7 George Marketing 4.2 1.4

Horizontal fragmentation:

Employee1 = (!
EmpNum <= 3
(Employee))
Employee2 = (!
EmpNum > 3
(Employee))

Vertical fragmentation

Employee1 =
EmpNum, Name
(Employee)
Employee2 =
EmpNum, DeptName,Salary,Tax
(Employee)


Data replication is another technique used to distribute data around the sites when
dealing with distributed database systems. In this technique copy of the data is stored in
another data set or database system. The data replication can be complete (where all sites
contain a copy of the data) or selective (where some data is partitioned for high locality
of reference and other less frequently updated data is copied to a number of sites). The
advantage of replication is that there is increased reliability as copies of the data are
stored in more than one site, this can be used as back up in case a site is corrupted or goes
down. Replication therefore adds to the robustness of the system. Further if the data item
is replicated on the sites which access it the most we have the advantage of high locality
of access which improves access performance. Further performance is in the parallelism
that is achieved running global queries concurrently at many sites. The disadvantages are
mainly centred on the problem with update performance and maintaining consistency.
Not only do locks need maintained for all the copies of a data item which need updating,
but the transaction management also becomes much more complex. Update performance
is therefore reduced because an update query cannot proceed until all copies are updated.
Furthermore to maintain the consistency of the data, integrity checking may take place
and if the check involves the replicated data it is carried out for each replication.
Therefore reducing performance further. Finally replicated data actually takes up more
storage resources.












Question 4



a) Consider the E-R diagram for property given below. Create and object relational
database system (ORDBS) schema using SQL-3 for it (60%).


























Model Answer:

Create row type AgentType
(AgentNum String,
Name char(30),
Address char(50),
Sex char(1));

Create row type PropertyType
(PropNum String,
BedNum Integer,
Agent
Person
Property
y
Flat
House
responsibl
e
contract
Is-A
Agent
# Name
Addres
s Sex
SSN
Addres
s
Name
Phone
Credit
Date_contr
Prop#
BedNu
mm
ZipC
Addres
s
Lease
Garden_siz
e
Floor
1
N N
N
Lease Integer,
ZipC String,
Address Char(50),
Is_Responsible_By ref(AgentType));

Create row type PersonType
(SSN String,
Name char(30),
Address char(50),
Phone Cchar(10),
Credit string);

Create row type HouseType
(Garden_Size String,
Under Property);

Create row type FlatType
(Floor String,
Under Property);

Create row type Contract
(PropNum ref(PropertyType),
PersonNum ref(PersonType),
DateContract String));

Create table Agent of type AgentType(
Primary key is AgentNum);

Create table Property of type PropertyType(
Primary key is PropertyNum,
Scope for Is_Responsible_By is Agent);

Create table House of type HouseType(
Under Property);

Create table Flat of type FlatType(
Under Property);

Create table Person of type PersonType(
Primary key is SSN);

Create table Contract of type ContractType(
Primary key is PropertyNum, PersonNum,
Scope for PropertyNum is Porperty,
Scope for PersonNum is Person);

b) List and explain 4 problems that exist when interoperating database systems (40%)


Model Answer:

Autonomy.
Design autonomy: the ability of a database system to choose its own design
related
to the data being managed, the representation of the data, and storage structures.

Participation autonomy: the ability of a database to associate and dissociate itself
from the system.

Communication autonomy: the ability of a database system to decide how and
when to communicate with other component database systems.

Execution autonomy: the ability of a database system to execute local operations
without interference from external operations.


Heterogeneity: a group of database systems with different local DBMS, with different
data models, and data manipulation/definition languages.


Semantic and syntactic conflicts: conflicts of name, scale, structure, representation,
sechematic discrepancies, different levels of abstraction.

Information discovery: locations and identification of information that is related, similar,
identical, or relevant to requested data. Many existing approaches assume that the
database systems know about the contents of other database systems.

S-ar putea să vă placă și