Professional Documents
Culture Documents
2020_SOLVED_DBMS
2020_SOLVED_DBMS
2020_SOLVED_DBMS
The database
must keep track of customers and their reservations, flights and their
status, seat assignments on individual flights, and the schedule and routing
of future flights. Your design should include a list of constraints, including
primary-key and foreign-key constraints.
Ans=>
Definition Primary Key is a unique and non- Candidate key is also a unique key to
null key which identify a record identify a record uniquely in a table
1
uniquely in table. A table can have but a table can have multiple
only one primary key. candidate keys.
Null Primary key column value can not be Candidate key column can have null
2
null. value.
Objective Primary key is most important part Candidate key signifies as which key
3
of any relation or table. can be used as Primary Key.
Use Primary Key is a candidate key. Candidate key may or may not be a
4
primary key.
The relation student is decomposed into following two new relations. Is this
decomposition lossless? Explain your answer.
Student_roll
Roll_No Name Student_department
123 Rohan Department Name
456 Rohan Comp Rohan
Science
Architecture Rohan
(b) Write down the SQL statements for the following queries:
(i) Find the names of the customers who have borrowed a car
manufactured by “TATA”.
(ii) Find the model of the car that is mostly being borrowed by the
customer.
(iii) In which year had most of the cars been manufactured?
(iv) Find the names of customers who have borrowed all cars
available in the car tables.
(v) Find the contact number of the customers who have borrowed at
least one car today.
Ans=> (i) SELECT cname FROM Customer NATURAL JOIN Borrow NATURAL JOIN Cars
WHERE manufacturer = “TATA”;
(ii) SELECT Model FROM Cars
WHERE reg_no IN ( SELECT reg_no FROM Borrow
WHERE COUNT(reg_no) = (SELECT MAX(COUNT(reg_no))
FROM Borrow GROUP BY reg_no));
(iii) SELECT year FROM cars
GROUP BY year HAVING COUNT(year) = (SELECT MAX(COUNT(year)) FROM cars
GROUP BY years);
(iv) SELECT cname FROM customer
WHERE cust_id IN (SELCT cust_id FROM Borrow
WHERE reg_no IN ALL (SELECT reg_no FROM cars));
(v) SELECT contact_no FROM customer NATURAL JOIN Borrow
WHERE date = SYSDATE();
T1 T2 T3
Read
Write
Read
Write
Read
Here, if Write in T1 failed, as the Read on T2 depends on the Write T1 so it gets wrong data if it’s not
cascading roll back. That’s why cascading roll back prevents dirty read from T2 and T3.
(c) Check whether the following two schedules are view
equivalent or not. Explain your answer.
Schedule 1 Schedule 2
T1 T2 T3 T1 T2 T3
Write(A) Write(A)
Write(A) Read(A)
Read(A) Write(A)
Ans=>
1. Initial read in Schedule 1 and Schedule 2 performed by T3 so it satisfies this condition.
2. Final write in Schedule 1 and Schedule 2 performed by T2 so it satisfies this condition.
3. In Schedule 1 Read(A) of T3 reads a different A, compared to the Read(A) of T3 in Schedule 2. In
S1, Read(A) is processed by Write(A) of T2 where in Schedule 2, Read(A) of T3 is processed by
Write(A) of T1. So it doesn’t satisfies this condition.
So, Schedule 1 and Schedule 2 do not satisfy all 3 conditions. Schedule 1 and Schedule 2 are not view
equivalent.
9. (a) In time stamp based protocol, if a transaction Ti wants to modify data item A, under which
condition it can modify A.
Ans=> There are three conditions:
1. Ts(Ti) < R-Ts(A): If Write(A) was expected to happen before the value of A is read, here
system assumes that it would never be modified so, the write operation rejected.
2. Ts(Ti) < W-Ts(A): If Ti is trying to write an absolute value of A, it gets rejected.
3. Otherwise Write(A) is executed W-Ts(A) is set to Ts(Ti).
This is the only condition where Ti is able to modify A.
(b) Write an algorithm to avoid deadlock.
Ans=> To avoid dead we have to remove these four conditions: 1. Mutual Exclusion, 2. Hold and
Wait, 3. No preemption, 4. Circular wait.
We can avoid deadlock by:
I. Eliminate Mutual Exclusion:
It is not possible to dis-satisfy the mutual exclusion because some resources, such as
the tape drive and printer, are inherently non-shareable.
II. Eliminate Hold and wait:
1. Allocate all required resources to the process before the start of its execution.
2. The process will make a new request for resources after releasing the current set
of resources.
III. Eliminate No Preemption:
Preempt resources from the process when resources required by other high priority
processes.
IV. Eliminate Circular Wait:
Each resource will be assigned with a numerical number. A process can request the
resources increasing/decreasing.
(c) Draw a wait-for graph for the following schedule and try to find out if there is any deadlock in the
system or not.
T1 T2 T3 T4 T5
Read(A)
Read(C)
Read(B)
Read(C)
Write(A)
Read(A)
Read(A)
Read(C)
Write(A)
Write(C)
Read(B)
Read(A)
Read(B)
Write(B)
Ans=>
A B C
R3 R2 R1
W3 R3 R5
R1 R5 R4
R2 W3 W4
W1
R4
10. (a) Explain 2-phase locking protocol. What is lock up-gradation and down- gradation?
Ans=> A transaction is said to follow Two Phase Locking protocol if Locking and Unlocking can be
done in two phases.
Growing Phase: New locks on data items may be acquired but none can be released.
Shrinking Phase: Existing locks may be released but no new locks can be acquired.
2PL enforces serialization and the serialization is done in the order of lock points. Lock points are
point of time where a transformation has obtained all locks.
Lock up-gradation: Converting an existing shared lock to exclusive lock.
Lock down-gradation: Converting an exclusive lock to a shared lock.
Schedule S1
T1 T2
Read(X)
Write(X)
Read(X)
Read(Y)
Write(X)
Write(Y)
Read(Y)
Write(X)
Ans=>
Schedules: R1(X), W1(X), R2(X), R1(Y), W2(X), W1(Y), R2(Y), W2(X)
To detect for any conflict in this schedule we need to check the precedence graph for ant cycle.
T1 T2