0% found this document useful (0 votes)
15 views

Numerical Questions

The document discusses practice problems based on view serializability. It provides solutions to check if schedules are view serializable or not. It also discusses concepts like conflict serializability and precedence graphs. The second half of the document discusses practice problems based on SQL and provides solutions involving creating tables and querying them. The last section provides problems on ER diagrams and relational calculus.

Uploaded by

Manish Kumar
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)
15 views

Numerical Questions

The document discusses practice problems based on view serializability. It provides solutions to check if schedules are view serializable or not. It also discusses concepts like conflict serializability and precedence graphs. The second half of the document discusses practice problems based on SQL and provides solutions involving creating tables and querying them. The last section provides problems on ER diagrams and relational calculus.

Uploaded by

Manish Kumar
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/ 14

PRACTICE PROBLEMS BASED ON VIEW

SERIALIZABILITY
[UNIT 4]
Problem 1. Check whether the given schedule S is view serializable or not.

Solution-
We know, if a schedule is conflict serializable, then it is surely view serializable. So, let us
check whether the given schedule is conflict serializable or not.

Checking Whether S is Conflict Serializable Or Not-


Step-01: List all the conflicting operations and determine the dependency between the
transactions-

W1(B) , W2(B) (T1 → T2)


W1(B) , W3(B) (T1 → T3)
W1(B) , W4(B) (T1 → T4)
W2(B) , W3(B) (T2 → T3)
W2(B) , W4(B) (T2 → T4)
W3(B) , W4(B) (T3 → T4)
Step-02: Draw the precedence graph-

• Clearly, there exists no cycle in the precedence graph.


• Therefore, the given schedule S is conflict serializable.
• Thus, we conclude that the given schedule is also view serializable.

Problem-02 Check whether the given schedule S is view serializable or not-


Solution-
We know, if a schedule is conflict serializable, then it is surely view serializable. So, let us
check whether the given schedule is conflict serializable or not.
Checking Whether S is Conflict Serializable Or Not-
Step-01: List all the conflicting operations and determine the dependency between the
transactions-
R1(A) , W2(A) (T1 → T2)
R2(A) , W1(A) (T2 → T1)
W1(A) , W2(A) (T1 → T2)
R1(B) , W2(B) (T1 → T2)
R2(B) , W1(B) (T2 → T1)

Step-02: Draw the precedence graph-

Clearly, there exists a cycle in the precedence graph. Therefore, the given schedule S is not
conflict serializable.
Now,
• Since, the given schedule S is not conflict serializable, so, it may or may not be view
serializable.
• To check whether S is view serializable or not, let us use another method.
• Let us check for blind writes.
Checking for Blind Writes-
• There exists no blind write in the given schedule S.
• Therefore, it is surely not view serializable.
Problem-03: Check whether the given schedule S is view serializable or not.
If yes, then give the serial schedule.
S : R1(A) , W2(A) , R3(A) , W1(A) , W3(A)

Solution- For simplicity and better understanding, we can represent the given schedule
pictorially as-

We know, if a schedule is conflict serializable, then it is surely view serializable. So, let us
check whether the given schedule is conflict serializable or not.
Checking Whether S is Conflict Serializable Or Not-
Step-01: List all the conflicting operations and determine the dependency between the
transactions-

R1(A) , W2(A) (T1 → T2)


R1(A) , W3(A) (T1 → T3)
W2(A) , R3(A) (T2 → T3)
W2(A) , W1(A) (T2 → T1)
W2(A) , W3(A) (T2 → T3)
R3(A) , W1(A) (T3 → T1)
W1(A) , W3(A) (T1 → T3)
Step-02: Draw the precedence graph-

Clearly, there exists a cycle in the precedence graph. Therefore, the given schedule S is not
conflict serializable. Since, the given schedule S is not conflict serializable, so, it may or may
not be view serializable.
To check whether S is view serializable or not, let us use another method. Let us check for
blind writes.
Checking for Blind Writes-
There exists a blind write W2 (A) in the given schedule S. Therefore, the given schedule S
may or may not be view serializable.
To check whether S is view serializable or not, let us use another method. Let us derive the
dependencies and then draw a dependency graph.

Drawing a Dependency Graph-


T1 firstly reads A and T2 firstly updates A.
So, T1 must execute before T2.
Thus, we get the dependency T1 → T2.
Final updation on A is made by the transaction T3.
So, T3 must execute after all other transactions.
Thus, we get the dependency (T1, T2) → T3.
From write-read sequence, we get the dependency T2 → T3

Now, let us draw a dependency graph using these dependencies-


• Clearly, there exists no cycle in the dependency graph.
• Therefore, the given schedule S is view serializable.
• The serialization order T1 → T2 → T3.

[NOTE- Blind Write- blind write is simply when a transaction writes without reading. i.e a
transaction have WRITE(Q), but no READ(Q) before it. So, the transaction is writing to the
database "blindly" without reading previous value.]

PRACTICE PROBLEMS BASED ON SQL


[UNIT 3]

Problem 1. Consider an EMPLOYEE relation, whose relation schema has


EMPLOYEE (employeename, Employeeid, Managerid, Dateofjoining, age,
city).
a. Write an SQL query to fetch all the fields of EMPLOYEE relation.
b. Write an SQL query to filter all employees who have an age 20 & a city of
London.
c. Write an SQL query to fetch name of all employees whose name starts with
r.

SOLUTON-
a) SELECT * from EMPLOYEE;
b) SELECT * from EMPLOYEE WHERE age = 20 AND city = ‘London’;
c) SELECT employeename from EMPLOYEE WHERE employeename
LIKE ‘r%’;
Problem 3. Write SQL statements for following:
Student (Enrno, name, courseId)
Course (courseId, coursename, duration)
a. Create student and course tables.
b. Insert 3 records in both student and course table.
c. Add column named city in student table.
d. Rename column named city to country in student table.

SOLUTON-
a) CREATE TABLE Student
(Enrno int (3), name varchar (20), courseId varchar (10)
);

CREATE TABLE Course


(CourseId varchar (10), coursename varchar (20), duration varchar
);

b) INSERT INTO Student VALUES (1, Nishant, KOE 067);


INSERT INTO Student VALUES (2, Neha, KEC 601);
INSERT INTO Student VALUES (3, Prashant, KEC 602);

INSERT INTO Course VALUES (KOE 067, database management


system, 12 hours);
INSERT INTO Course VALUES (KEC 601, digital communication, 10
hours);
INSERT INTO Course VALUES (KEC 602, control system, 15 hours);

c) ALTER TABLE Student ADD City (char (10));

d) ALTER TABLE Student RENAME COLUMN City TO Country;


PRACTICE PROBLEMS BASED ON E-R DIAGRAM
[UNIT -1]
Problem 1. Draw E-R diagram for College Database. Reduce this E-R diagram
into Tables.
Solution-
E-R diagram of College Database
Reduction of E-R diagram to Tables
PRACTICE PROBLEMS BASED ON RELATIONAL
CALCULUS
[UNIT -2]

A Relational Model for Films


The following DDL declarations and table data describe a relational model for the film industry.

create table Actor (


actorId varchar(5),
name varchar(50),
nationality varchar(20),
age integer,
primary key (actorId)
)

create table Film (


_lmId varchar(5),
title varchar(50),
year integer,
directorId varchar(5),
primary key (_lmId),
foreign key (directorId) references Director
)

create table Performance (


actorId varchar(5),
_lmId varchar(5),
character varchar(50),
primary key (actorId, _lmId),
foreign key (actorId) references Actor,
foreign key (_lmId) references Film
)

create table Director (


directorId varchar(5),
name varchar(50),
nationality varchar(20),
primary key (directorId)
)
Example 1: Operations in Relational Algebra
For each of the following queries in relational algebra, calculate the output table
and give a brief statement of what query it answers.
i. age > 45(Actor)
ii. title (Film)
iii. title ( year<2000(Film))
iv. year<2000(Film) U year<2010(Film)
v. year<2000(Film) Ո year<2010(Film)

Solution
i. age > 45(Actor)
Retrieves details of all actors above the age of 45. The output table is as
follows:

ii. title (Film)


Retrieves all distinct film titles. The output table is as follows:

iii. title ( year<2000(Film))


Retrieves all distinct titles of films that were released before 2000.
The output table is as follows:
iv. year<2000(Film) U year<2010(Film)
Retrieves details of all films released before 2000 or after 2010. The output
table is as follows:

v. year<2000(Film) Ո year<2010(Film)

Retrieves details of all films released between 2000 and 2010. The output table
is as follows:

Example 2: Constructing Queries

For each of the following questions, formulate the specified queries in tuple-
relational calculus and as a computation in relational algebra.

a) Retrieve details of all films that were released in 2010. The output schema
should be the same as that of the Film table.
b) Retrieve details of all actors that are not in their thirties. The output schema
should be the same as that of the Actor table.
c) Retrieve the names of all directors.
d) Retrieve the names of all American directors.
e) Find out the names of all British actors above the age of 40.
Solution –
a) Retrieve details of all films that were released in 2010. The output schema
should be the same as that of the Film table.

year<2000(Film)
b) Retrieve details of all actors that are not in their thirties. The output schema
should be the same as that of the Film table.
(age<30) U (age>39) (Actor)
or
age<30(Actor) U year>39(Actor)
c) Retrieve the names of all directors.

title (Film)

d) Retrieve the names of all American directors.

name ( nationality = ‘American’ (Director))


e) Find out the names of all British actors above the age of 40.

name ( (nationality = ‘American’ ˄ age > 40) (Director))

You might also like