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

DBMS - Paper Solution - CSC403 - R19 - Sem IV

DBMS_Paper solution_CSC403_R19_sem IV

Uploaded by

yashpatilyp2004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

DBMS - Paper Solution - CSC403 - R19 - Sem IV

DBMS_Paper solution_CSC403_R19_sem IV

Uploaded by

yashpatilyp2004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Q2 Solve any Two Questions out of Three 10 marks each

A What are different database users? Give responsibilities of

DBA Database Users

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.

1. Application Programmers – They are the developers who interact


with the database by means of DML queries. These DML queries
are written in the application programs like C, C++, JAVA, Pascal
etc. These queries are converted into object code to communicate
with the database. For example, writing a C program to generate
the report of employees who are working in particular department
will involve a query to fetch the data from database. It will
include a embedded SQL query in the C Program.
2. Sophisticated Users – They are database developers, who write
SQL queries to select/insert/delete/update data. They do not use
any application or programs to request the database. They directly
interact with the database by means of query language like SQL.
These users will be scientists, engineers, analysts who thoroughly
study SQL and DBMS to apply the concepts in their requirement.
In short, we can say this category includes designers and
developers of DBMS and SQL.
3. Specialized Users – These are also sophisticated users, but they
write special database application programs. They are the
developers who develop the complex programs to the requirement.
4. Stand-alone Users – These users will have stand –alone database
for their personal use. These kinds of database will have
readymade database packages which will have menus and
graphical interfaces.
5. Native Users – these are the users who use the existing application
to interact with the database. For example, online library system,
ticket booking systems, ATMs etc which has existing application
and users use them to interact with the database to fulfill their
requests.
Database Administrators

The life cycle of database starts from designing, implementing to


administration of it. A database for any kind of requirement needs to be
designed perfectly so that it should work without any issues. Once all
the design is complete, it needs to be installed. Once this step is
complete, users start using the database. The database grows as the data
grows in the
database. When the database becomes huge, its performance comes down.
Also accessing the data from the database becomes challenge. There will
be unused memory in database, making the memory inevitably huge.
These administration and maintenance of database is taken care by
database Administrator – DBA.
A DBA has many responsibilities. A good performing database is in
the hands of DBA.
∙ Installing and upgrading the DBMS Servers: – DBA is
responsible for installing a new DBMS server for the new
projects. He is also responsible for upgrading these servers as
there are new versions comes in the market or requirement. If
there is any failure in upgradation of the existing servers, he
should be able revert the new changes back to the older version,
thus maintaining the DBMS working. He is also responsible for
updating the service packs/ hot fixes/ patches to the DBMS
servers.
∙ Design and implementation: – Designing the database and
implementing is also DBA’s responsibility. He should be able to
decide proper memory management, file organizations, error
handling, log maintenance etc for the database.
∙ Performance tuning: – Since database is huge and it will have lots
of tables, data, constraints and indices, there will be variations in
the performance from time to time. Also, because of some
designing issues or data growth, the database will not work as
expected. It is responsibility of the DBA to tune the database
performance. He is responsible to make sure all the queries and
programs works in fraction of seconds.
∙ Migrate database servers: – Sometimes, users using oracle would
like to shift to SQL server or Netezza. It is the responsibility of
DBA to make sure that migration happens without any failure,
and there is no data loss.
∙ Backup and Recovery: – Proper backup and recovery programs
needs to be developed by DBA and has to be maintained him.
This is one of the main responsibilities of DBA. Data/objects
should be backed up regularly so that if there is any crash, it
should be recovered without much effort and data loss.
∙ Security: – DBA is responsible for creating various database users
and roles, and giving them different levels of access rights. ∙
Documentation: – DBA should be properly documenting all his
activities so that if he quits or any new DBA comes in, he should be
able to understand the database without any effort. He should
basically maintain all his installation, backup, recovery, security
methods. He should keep various reports about database
performance.
B Produce ER Diagram from the following relational database Schema.
C Book( book_id, title,author, cost)
Store(store_no, city, state, inventory_val)
Stock(store_no, book_id,quantity)

Consider above relational schema and formulate SQL queries for the
following:

(i)Modify the cost of DBMS books by 10%

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;

(iii)Find the title of the most expensive book

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)

(iv)Find the total quantity of books in each store

Select quantity from stock group by store _no;

(v) Add a new record in Book(Assume values as per requirement)


Insert into Book values (11234,’Computer
Network’,’Navathe’,550);
Q3 Solve any Two Questions out of Three 10 marks each
A Consider a dependency diagram of relation R and normalize it up to third
normal form.

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

Third normal form:


A relation is in third normal form, if there is no transitive
dependency for non-prime attributes as well as it is in
second normal form.
A relation is in 3NF if at least one of the following condition
holds in every non-trivial function dependency X –> Y:
1. X is a super key.
2. Y is a prime attribute (each element of Y is part of some
candidate key).

A relation that is in First and Second Normal Form and in


which no non-primary-key attribute is transitively dependent
on the primary key, then it is in Third Normal Form (3NF).

Proj_no and Emp_no are candidate keys so they are prime attribute

Non prime attributes are


Proj_name, Emp_name,, Job_class, Chg_hr, Hrs_billed

Given
Proj_no → Emp_no
Emp_no → Emp_name, Job_class, Chg_hr

Therefore by transitivity rule


Proj_no → Emp_name, Job_class, Chg_hr
Also

Proj_no → Proj_name
Proj_name → Emp_name,, Job_class, Chg_hr, Hrs_billed

Therefore by transitivity rule


Proj_no → Emp_name,, Job_class, Chg_hr, Hrs_billed

By avoiding transitivity we will consider

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.

∙ A conflict between Ii and Ij forces a temporal order between them.


∙ If Ii and Ij are consecutive in a schedule and they do not conflict,
their results would remain the same even if they had been
interchanged in the schedule.

T3 T4

Read(P)

Write(P)
Write(P)

∙ Ifa schedule Scan be transformed in to a


schedule S by a series of swaps of
non-conflicting instructions, then S and S` are
conflict equivalent.
∙ In other words a schedule Sis conflict
serializable if it is conflict equivalent to a serial
schedule.
∙ Example of a schedule that is not conflict
serializable:

∙ The instructions cannot be swapped in the


above schedule to obtain either the serial
schedule < T 3 , T 4 >, or the serial schedule < T
4 ,T 3 >.
∙ A serial schedule T2 follows T1, by a series of
swaps of non conflicting instructions making the
below Schedule conflict serializable.

∙ 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

write(P) operation in schedule S`.

o View equivalence is also based purely on reads and


writes alone.
o A schedule S is view serializable if it is ie w equivalent to
a serial schedule.
o Every conflict serializable schedule is also view
serializable. o Every view serializable schedule which is not
conflict
serializable has blind writes.
C Explain deadlock handling in DBMS with suitable examples.

In a database, a deadlock is an unwanted situation in which two or more


transactions are waiting indefinitely for one another to give up locks.
Deadlock is said to be one of the most feared complications in DBMS as
it brings the whole system to a Halt.
Example – let us understand the concept of Deadlock with an example :
Suppose, Transaction T1 holds a lock on some rows in the Students table
and needs to update some rows in the Grades table. Simultaneously,
Transaction T2 holds locks on those very rows (Which T1 needs to
update) in the Grades table but needs to update the rows in the Student
table held by Transaction T1.
Now, the main problem arises. Transaction T1 will wait for transaction
T2 to give up lock, and similarly, transaction T2 will wait for transaction
T1 to give up the lock. As a consequence, All activity comes to a halt and
remains at a standstill forever unless the DBMS detects the deadlock and
aborts one of the transactions.
Deadlock in DBMS

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.

∙ Wound Wait Scheme –


In this scheme, if an older transaction requests for a resource held by
younger transaction, then older transaction forces younger transaction
to kill the transaction and release the resource. The younger
transaction is restarted with minute delay but with same timestamp. If
the younger transaction is requesting a resource which is held by
older one, then younger transaction is asked to wait till older releases
it.

You might also like