DBMS - Paper Solution - CSC403 - R19 - Sem IV
DBMS - Paper Solution - CSC403 - R19 - Sem IV
Database users are the one who really use and take the benefits of
database. There will be different types of users depending on their need
and way of accessing the database.
Consider above relational schema and formulate SQL queries for the
following:
Update Book
Set cost=cost+cost*0.1
Where Book.title=’DBMS’;
(ii)Find the author of the books which are available in Mumbai store
Select author
From Book,Store,Stock
Where store.city=’Mumbai’ and stock.store_no=stor.store_no and
Book.book_id=Stock.book_id;
Select title from Book where cost > (select cost from Book);
Select title from Book as B where (select count(*) from book as T where
t.price>b.price)
Proj_no → Proj_name
Proj_no → Emp_no
Emp_no → Emp_name, Job_class, Chg_hr
Job_class → Chg_hr
Proj_name → Emp_name,, Job_class, Chg_hr, Hrs_billed
Proj_no and Emp_no are candidate keys so they are prime attribute
Given
Proj_no → Emp_no
Emp_no → Emp_name, Job_class, Chg_hr
Proj_no → Proj_name
Proj_name → Emp_name,, Job_class, Chg_hr, Hrs_billed
Proj_no → Proj_name
Emp_no → Emp_name, Job_class, Chg_hr, Hrs_billed
B Explain conflict and view serializability with suitable
examples . A schedule is serializable if it is equivalent to a
serial schedule.
∙ Conflict serializability:
o Instructions Ii and Ij, of transactions Ti and Tj
respectively, conflict if and only if there exists some item P
accessed by both Ii and Ij, and atleast one of these
instructions wrote P. o Consider the below operations
i. Ii = read(P), Ij = read(P). Ii and Ij don’t conflict.
ii. Ii = read(P), Ij = write(P). They conflict.
iii. Ii = write(P), Ij = read(P). They conflict.
iv. Ii = write(P), Ij = write(P). They conflict.
T3 T4
Read(P)
Write(P)
Write(P)
∙ View serializability:
o S and S` are view equivalent if the following
three
conditions are met:
i. For each data item P, if transaction Ti reads the
initial
value of P in schedule S, then transaction Ti transaction Ti must in schedule S` also read the
must, in value of P that was produced by transaction Tj.
schedule S`, also read the initial value of P.
iii. For each data item P, the transaction that
ii. For each data item P, if transaction Ti performs the final write(P) operation in
executes read (P)in schedule S, and that value schedule S must perform the final
was produced by transaction Tj, then
Deadlock Avoidance –
When a database is stuck in a deadlock, It is always better to avoid
the deadlock rather than restarting or aborting the database.
Deadlock avoidance method is suitable for smaller databases
whereas deadlock prevention method is suitable for larger databases.
One method of avoiding deadlock is using application-consistent logic. In
the above given example, Transactions that access Students and Grades
should always access the tables in the same order. In this way, in the
scenario described above, Transaction T1 simply waits for transaction T2
to release the lock on Grades before it begins. When transaction T2
releases the lock, Transaction T1 can proceed freely.
Another method for avoiding deadlock is to apply both row-level locking
mechanism and READ COMMITTED isolation level. However, It does
not guarantee to remove deadlocks completely.
Deadlock Detection –
When a transaction waits indefinitely to obtain a lock, The database
management system should detect whether the transaction is involved in
a deadlock or not.
Wait-for-graph is one of the methods for detecting the deadlock
situation. This method is suitable for smaller database. In this method a
graph is drawn based on the transaction and their lock on the resource. If
the graph created has a closed loop or a cycle, then there is a deadlock.
For the above mentioned scenario the Wait-For graph is drawn below
Deadlock prevention –
For large database, deadlock prevention method is suitable. A deadlock
can be prevented if the resources are allocated in such a way that
deadlock never occur. The DBMS analyzes the operations whether
they can create deadlock situation or not, If they do, that transaction is
never allowed to be executed.
Deadlock prevention mechanism proposes two schemes :
∙ Wait-Die Scheme –
In this scheme, If a transaction request for a resource that is locked
by other transaction, then the DBMS simply checks the timestamp
of both transactions and allows the older transaction to wait until the
resource is available for execution.
Suppose, there are two transactions T1 and T2 and Let timestamp
of any transaction T be TS (T). Now, If there is a lock on T2 by
some other transaction and T1 is requesting for resources held by
T2, then DBMS performs following actions:
Checks if TS (T1) < TS (T2) – if T1 is the older transaction and T2
has held some resource, then it allows T1 to wait until resource is
available for execution. That means if a younger transaction has
locked some resource and older transaction is waiting for it, then older
transaction is allowed wait for it till it is available. If T1 is older
transaction and has held some resource with it and if T2 is waiting for
it, then T2 is killed and restarted latter with random delay but with the
same timestamp. i.e. if the older transaction has held some resource
and younger transaction waits for the resource, then younger
transaction is killed and restarted with very minute delay with same
timestamp.
This scheme allows the older transaction to wait but kills the younger
one.