Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
37 views25 pages

Winter 2020 Paper Solution - Dbms

H J J J J

Uploaded by

Jaypalsinh Rana
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)
37 views25 pages

Winter 2020 Paper Solution - Dbms

H J J J J

Uploaded by

Jaypalsinh Rana
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/ 25

DBMS WINTER 2020 SOLUTION

Q1 (A) Define following terms : 1) Schema 2) DBMS 3)Physical Data


Independence (3M)
ANS
1) Schema
 A database schema is a structured that represents the logical
storage of the data in a database. It contains schema objects
that may include tables, fields, pages, view, relationship,
primary key, foreign key

2) Database Management System


 Database management system is a collection of interrelated

z
data and various programmes that are used to handle that data

3) Physical Data Independence


aa
Aw
 This is the kind of data independence which allows the
modification of physical schema without requiring any change
to the conceptual schema
ut

Q1 (B) Describe tasks performed by Database Administrator (4M)


gr

ANS
Ja

 A database administrator (DBA) is a person or a group in charge of


implementing DBMS in an organization. The DBA job requires a high
degree of technical expertise, DBA consist of team of people rather
than just one person
 Primary role of DBA is as follows
 Database design
 Performance Issues
 Database accessibility
 Capacity issues
 Data Replication
 Table Maintenance
 Responsibilities of DBA
 Makes the decision concerning the content of the database

Click :Youtube Channel | Free Material | Download App


 Plans the storage structure and access strategy
 Provide the support to the users
 Defines the security and integrity checks
 Interpreter backup and recovery strategies
 Monitoring the performance responding to changes in
requirements

Q1 (C) Difference between Strong Entity Set & Weak Entity Set.
Demonstrate concept of both using real – time example using E – R
diagram (7M)

ANS

Strong Entity Set Weak Entity Set


Strong Entity Set always has While a weak entity has partial

z
primary key discriminator key
Strong entity is not dependent on
any other entity
aa
Weak entity depends on strong
entity
Aw
Strong entity is represented by a Weak Entity is represented by
single rectangle double rectangle
Two strong entities relationship is While relation between one strong
ut

represented by single diamond and one weak entity is


gr

represented by double diamond


Strong entities have either total While weak entity always has total
Ja

participation or not participation

Strong Entity

Click :Youtube Channel | Free Material | Download App


Weak Entity

Q2s (A) Consider relation R = {E, F, G, H, I, J, K, L, M, N} and set of


functional dependencies (3M)

z
{{E, F} → {G} , {F} → {I}, {R, H} → {K, C} , K → {M} on R. What is key of R?

ANS
aa
Aw

Functional Dependencies
EF → G , F → IJ, EH → KL, K → M, L → N
ut

Here, EFH is missing in RHS


gr

{EFH}+ = {E, F, H}
Ja

{EFH}+ = {E, F, G, H} (EF → G)


{EFH}+ = {E, F, G, H, I} (F → IJ)
{EFH}+ = {E, F, G, H, I, K, L} (EH → KL)
{EFH}+ = {E, F, G, H, I, J, K, L, M, N} (K → M, L → N)

So, here key for R is {E, F, H} which is candidate key

Q2 (B) Consider relational schema R = (A, B, C, D, E, H) on which of


following functional dependencies hold : A → B, BC → D, E → C, D → A.
What are candidate keys of R? (4M)
ANS

Functional Dependencies
A → B, BC → D, E → C, D → A

Click :Youtube Channel | Free Material | Download App


Here for {AEH}+ = {A, E, H}
{AEH}+ = {A, B, E, H} (A → B)
+
{AEH} = {A, B, C, E, H} (E → C)
+
{AEH} = {A, B, C, D,E, H} (BC → D)
+
So, here {AEH} is super key
So {AEH}+ is candidate key

Here A is replaced by D
{DEH}+ = {D, E, H}
{DEH}+ = {A,D, E, H} (D → A)
+
{DEH} = {A, B,D, E, H} (A → B)
+
{DEH} = {A, B,C,D, E, H} (E → C)
+
So here {DEH} is super key
So {DEH}+ is candidate key

z
Here D is replaced by BC aa
{BCEH}+ = {B, C, E, H}
{BCEH}+ = {B, C,D, E, H} (BC → D)
Aw
+
{BCEH} = {A,B, C,D, E, H} (D → A)
+
So here {BCEH} is super key
So {BEH}+ is candidate key
ut
gr

So, here B is replaced by A


{ACEH}+ = {A, C, E, H}
Ja

{ACEH}+ = {A, B,C, E, H} (A → B)


{ACEH}+ = {A, B,C, D,E, H} (BC → D)
It is not candidate key

{BEH}+ = {B, E, H}
{BEH}+ = {B, C,E, H} (E → C)
+
{BEH} = {A, B, C,D, E, H} (BC → D, D → A)
So, {BEH}+ is a candidate key

Candidate Keys : {AEH}, {DEH}, {BEH}

Click :Youtube Channel | Free Material | Download App


Q2(C) Draw an ER diagram for following scenario. Make necessary
assumptions and clearly note down same. We would like to make our
college’s manually operated library to fully computerized (7M)

ANS

z
aa
Aw
ut
gr
Ja

Click :Youtube Channel | Free Material | Download App


Q3(A) Define terms : (1) Primary Key (2) Super key (3M)

ANS

Primary Key
 The primary key is a candidate key chosen by database designer to
identify the tuple in relation uniquely
 For example : consider the following representation of primary key in
the student table

z
aa
Aw

Super Key
 It set of one or more attributes within table that can uniquely identify
ut

each record within table


 For example : Consider student table as follows
gr
Ja

Q3(B) List types of joins in relational algebra (4M)

ANS

Click :Youtube Channel | Free Material | Download App


Natural Join
 Natural join is a set of tuples of all combinations in R & S that are
equal on their common attributes name
 It is denoted by ⋈
 Example

Inputs :
ΠEmp_name, salary (Employee ⋈ Salary)
Output :
Emp_name Salary

z
Stephan 50000 aa
Jack 30000
Aw
Harry 25000

Outer Join
ut

 Outer Join operation is an extension of Join Operation. It is used to


gr

deal with missing information


 Example
Ja

Click :Youtube Channel | Free Material | Download App


Equijoin
 It is also known as Inner Join. It is most common Join. It is based on
matched data as per equality condition. The Equi Join uses the
comparison operator (=)
 Example
Customer
Class _id Name
1 John
2 Harry
3 Jackson

Product
Product_id Name
1 Delhi
2 Mumbai

z
3 Noida aa
Customer ⋈ Product
Aw

Customer Product
Class _id Name Product_id Name
1 John 1 Delhi
ut

2 Harry 2 Mumbai
gr

3 Jackson 3 Noida
Ja

Q3(C) Which operator is used “For All” types of queries. Explain (7M)

ANS
 ALL & ANY all logical operations in SQL. They return boolean value as
result
 ALL operator is used to select all tuples of select statement. It is also
used to compare a value to every value in another value set or result
from a subquery
 The ALL operator returns true of all the sub queries meet the
condition. The ALL must be preceded by comparison operators and
evaluates true if all of the subqueries value meet the condition. All is
used with select, where having statement
 All with select statement
Syntax :
select all field_name

Click :Youtube Channel | Free Material | Download App


from table_name
where condition(s);

 All with where or having statement


Syntax :
select column_name(s)
from table_name
where column_name. comparison_operator ALL
(select column_name
From table_name
where condition(s);)

 Example
Consider following product table
ProductID ProductName Price Supplied_id Category ID

z
1 Chais 18 aa 1 1
2 Chang 19 1 1
3 Aniseed syrup 10 1 2
Aw

4 Mishi Kobe 97 4 6

 Queries
ut

Find name of all product


gr

Query : select all productname from products where TRUE;


Output :
Ja

ProductName
Chais
Chang
Aniseed syrup
Mishi Kobe

Find name of product if all records ordered details has quantity


either equal to 8 or 2
Order details table :
Order details ID OrderID Product ID Quantity
1 10248 1 12
2 10248 2 10
3 10249 3 15
4 10249 4 8

Click :Youtube Channel | Free Material | Download App


Query :
select productname
from products
where productID = All (select productID
from orderdetails
where Quantity = 8 OR
Quantity = 2);
Output :
ProductName
Mishi Kobe

Find orderID where maximum quantity among all product so that


orderID is greater than average quantity of all orderID
Query :
select orderID from orderdetails

z
Group by orderID having max(Quantity) > All
aa
(select avg(Quantity) from orderdetails Group by OrderID);
Aw

Output :
Order ID
10248
ut
gr

Q4(A) Define terms : a) Foreign Key b)Candidate Key (3M)


Ja

ANS
a) Foreign Key
 Foreign key is a single attribute or a collection of attributes in one
table that refers to the primary key of another table
 Thus foreign keys refers to primary key
 The table containing the primary keys called parent table and the
table containing foreign keys is called child table
 Example :

Click :Youtube Channel | Free Material | Download App


b) Candidate Key
 The candidate key is subset of superset. In other words candidate
key is a single attribute or least or minimal combination of
attributes that uniquely identify each record in table
 Example : In given student table, candidate key is RegNo(RollNo,
Phone)

Q4(B) List unary relational operators & explain with example (4M)
ANS
 select, project, rename comes under unary operators

z
 select operation aa
 This operation is used to fetch the Rows or tuples from table
 Syntax :σpredicate(relation)
Aw

where σ represents select operation. The predicate denotes some


logic using which data from relation is selected
 For example : Consider relation as follows
ut

cid cname Age Gender


gr

1 Ram 21 Male
2 Shyam 18 Male
Ja

3 Seeta 16 Female
4 Geeta 23 Female
Query : Fetch students with age more than 18
σage>18(student)
 Project
 Projection operation is used to project only a certain set of
attributes of a relation
 Thus to display particular column from a relation projector operator
is used
 Syntax : πC1,C2,…(r) where C1, C2 etc are attributes name
 Example :
Query : Display name & age of all students
Πsname,age(student)

Click :Youtube Channel | Free Material | Download App


sname age
Ram 21
Shyam 18
Seeta 18
Geeta 23
 Rename
 This operation is used to rename the output relation for any query
operation which returns result like select, project etc to simplify
rename a relation(table)
 Operator ρ(rho) is used for renaming
 Syntax : ρ(relationNew, relationOld)
 Example :
Query : Create relation student names with sid & sname from
student
ρ(student_names, (πsid,sname(student))

z
aa
Q4(C) Consider the following relational database schema consisting of
the four relation schemas:
Aw
passenger ( pid, pname, pgender, pcity)
agency ( aid, aname, acity)
flight (fid, fdate, time, src, dest)
ut

booking (pid, aid, fid, fdate)


Answer the following questions using relational algebra queries.
gr

a) Get the details about all flights from Chennai to New Delhi
Ja

b) Get the complete details of all flights to New Delhi


c) Find the passenger names for passengers who have bookings on
at least one flight.

ANS

a) Get the details about all flights from Chennai to New Delhi
σsrc=”Cheenai” ^ dest = “New Delhi” (flight)

b) Get the complete details of all flights to New Delhi


σdestination=”New Delhi” (flight)

c) Find the passenger names for passengers who have bookings on at


least one flight
Πpname(passenger ⋈ booking)

Click :Youtube Channel | Free Material | Download App


Q5 (A) List and explain ACID properties with respect to database (3M)

ANS

1) Atomicity
 This property states that each transaction must be considered
as a single unit and must be fully completed or not completed
at all
 No transaction in the database is left half completed
 Database should be in state either before the transaction
execution or after transaction execution. It should not be in
state executing
2) Consistency
 The database must remain consistent state after performing any
transaction

z
3) Isolation aa
 In a database system where more than one transactions are
being executed simultaneously and in parallel the property of
Aw

isolation states that all the transactions will be carried out an


executed as if it is the only transaction in the system
 No transaction will affect the existence of any other transaction
ut

4) Durability
gr

 The database should be strong enough to handle any system


failure
Ja

 If there is any set of insert/update then it should be able to


handle and commit to the database
 If there is any failure the database should be able to recover it
to consistent state

Q5 (B) Explain RAID levels with respect to Data Storage (4M)

ANS

 RAID refers to redundancy array of the independent disk


 It is a technology which is used to connect multiple secondary storage
device for increased performance data redundancy or both
 There are 7 levels of RAID schemes. These schemas are RAID0, RAID1,
… RAID6

Click :Youtube Channel | Free Material | Download App


 RAID 0 :
 RAID level 0 provides data stripping i.e a data can placed across
multiple disks. It is based on stripping that means if one disk fails
then all the data in the array is lost
 This level doesn’t provide fault tolerance but increases system
performance

 RAID 1 :
 This level is called mirroring of data as it copies the data from
drive 1 to drive 2
 It provides 100% redundancy in case of failure

 RAID 2 :
 RAID 2 consist of bit level stripping using hamming code parity.

z
aa
In this level, each data bit in word is recorded on separate disk
and ECC code of data words is stored on different set disks
Aw
 Due to its high cost & complex structure, this level is not
commercially used
ut

 RAID 3 :
gr

 RAID 3 consists of byte – level stripping with dedicated parity. In


this level, parity information is stored for each disk section &
Ja

written to dedicated parity drive

 RAID 4 :
 RAID 4 consists of block level stripping with parity disk instead of
duplicating data, RAID 4 adopts parity – based approach

 RAID 5 :
 RAID 5 is slight modification of RAID4 system. The only difference
is that in RAID 5 the parity rotates among device

 RAID 6 :
 This level is an extension of RAID 5. It contains block – level
stripping with 2 parity bits

Click :Youtube Channel | Free Material | Download App


Q5 (C) Explain concept of Conflict Serializable with schedules (7M)

ANS

 A schedule is called Conflict Serializability if after swapping of non


conflicting operations it can transfer into a serial schedule
 The schedule will be conflict serializable if it is conflict equivalent to a
serial schedule
 The 2 operations become conflicting if all the conditions satisfy
1. Both belong to separate transaction
2. They have the same data item
3. They contain at least one write operation
 Example
Swapping is possible only if S1 and S2 are logically equal

z
1) T1 : Read(A) T2 : Read (A)
aa
Aw

Here, S1 = S2 that means it is non conflict


ut
gr

2) T1 : Read(A) T2 : Write(A)
Ja

Here,S1 ≠ S2 that means it is conflict

3) T1 : Write(A) T2 : Read(A)

Here,S1 ≠ S2 that means it is conflict

Click :Youtube Channel | Free Material | Download App


4) T1 : Write(A) T2 : Write(A)

Here,S1 ≠ S2 that means it is conflict


 In the conflict equivalent one can be transformed to another by
swapping non conflicting operations. In given example, so it is conflict
equivalent S1 (S1 can be executed to S2) by swapping non – conflicting
operations
 Example :

z
aa
Aw

Schedule S2 is a serial schedule because in this all operations of T1 is


performed before starting any operation of T2 schedule S1 can be
ut

transferred in a serial schedule by swapping non – conflicting


gr

operations
Ja

Q6 (A) List & explain types of locks in transaction (3M)

ANS
There are two types of lock :
1) Shared Lock
 It is also known as Read only lock
 In shared lock, data item can only read by transaction
 It can be shared between transactions because when transaction
holds a lock, then it can’t update data on data item
2) Exclusive Lock
 In the exclusive lock, data item can be both read as well as return
by the transaction
 This lock is exclusive and in this lock multiple transactions do not
modify the some data simultaneously

Click :Youtube Channel | Free Material | Download App


Q6 (B) With neat diagram explain data storage hierarchy (4M)

ANS
 Data may be logically organised bits, characters, fields, records, file &
databases
1) Bits : Bits is the smallest unit of data. The computer can store in
a database. It is represented by zero of and one for on

2) Character (bytes) : A character is a letter, number or special


character. Example : a, b, 1,+ etc

3) Field : a field consists of grouping of characters. For example :


person firstname, streetaddress etc

z
4) File : a file is a collection of related record. Example : An
aa
employee file world contains records of employees of firms
Aw

5) Record : A record is a collection of related field. Example payroll


for a person
ut

6) Database : A database is a logically organised collection of


gr

related data design build for specific purpose or database is an


integrated collection of logically related records or objects
Ja

Click :Youtube Channel | Free Material | Download App


Q6 (C) Explain deadlock with suitable scheduling (7M)

ANS
Deadlock
 A deadlock is the condition where 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 no task ever
set finished and is in waiting state forever
 Example : In the student table, transaction T1 holds a lock on some
rows and need to update some rows in grade table. Simultaneously,
transaction T2 holds locks on some rows in the grade table & needs
to update rows in student table held by transaction T1
 Now main problem arises. Now transaction T1 is waiting for
transaction T2 to release its lock and similarly transaction T2 is

z
aa
waiting for T1 to release its lock. All activities come to half state n
remain at standstill. It will remain in standstill until the DBMS detects
Aw
the deadlock and aborts one of the transaction
ut
gr

 Deadlock Avoidance
Ja

 When a database is stuck in deadlock state, it is better to avoid


the database rather than avoiding or restarting the database.
This is waste of time and resources
 Deadlock avoidance mechanism is used to detect any deadlock
situation in advance. A method like wait for graph is used for
detecting the deadlock situation but this method is suitable
only for the smaller database. For longer database deadlock
prevention method can be used
 Deadlock Detection
 In database when a transaction waits indefinitely to obtain a
lock, then the DBMS should detect whether the transaction is
involved in deadlock or not. The lock manager maintains await
for graph to detect deadlock cycle in database

Click :Youtube Channel | Free Material | Download App


 Wait for Graph
 This is the suitable method for deadlock detection. In this
method a graph created based on the transaction and
their lock. If the created graph has a cycle or closed loop,
then there is a deadlock
 The wait for graph is maintained by the system for every
transaction which is waiting for some data held others.
The system keeps checking a graph if there is any cycle in
the graph
 Wait for graph for above scenario is checked

z
aa
Q7(A) Explain following SQL command : GRANT & REVOKE (3M)
Aw

ANS
ut

Grant
gr

 SQL grant is a command used to provide access or privileges on


database object to users
Ja

 Syntax :
GRANT privilege_name
ON object_name
TO{user_name|public|rolename}
{with grant option}
 privilege _name : Access right on privilege granted to user. Some of
access rights are ALL, EXECUTE and SELECT
object_name : Name of database object like TABLE, VIEW, STORED
PROC
user_name : Name of user to whom on access right is being granted
PUBLIC : To grant access rights to all users
ROLES : Set of privileges grouped together
WITH GRANT OPTION : Allows user to grant access rights to other
users

Click :Youtube Channel | Free Material | Download App


Revoke
 REVOKE command removes user access rights or privileges to
database objects
 Syntax :
REVOKE privilege_name
ON object_name
FROM {user_name|public|role_name}

Q7(B) (4M)

z
aa
a) Find out unique values of DEPARTMENT from Worker table
Aw
b) Print details of Workers whose SALARY lies between 10, 000 &
50,000
c) Print details of workers who have joined in Feb 2014
ut

d) Fetch workers names with salaries >=50,000 and < = 10,000


gr

ANS
Ja

a) Find out unique values of DEPARTMENT from Worker table


SELECT DISTINCT DEPARTMENT FROM Worker;

b) Print details of Workers whose SALARY lies between 10000 & 50,000
SELECT * FROM Worker
WHERE SALARY BETWEEN 100000 AND 500000;

c) Print details of workers who have joined in Feb 2014


SELECT *FROM Worker
WHERE JOINING_DATE >= '2014-02-01' AND JOINING_DATE < '2014-
03-01';

d) Fetch workers names with salaries >=50,000 and < = 10,000


SELECT FIRST_NAME, LAST_NAME FROM Worker
WHERE SALARY >= 50000 AND SALARY <= 100000;

Click :Youtube Channel | Free Material | Download App


Q7(C) Write short note on Query Processing (7M)

ANS

Steps involved in query processing


1) Parsing & Translation
2) Optimization
3) Evaluation

1. Parsing & Translation


 A query processing includes certain activities for data retrieval
 Initially the given user queries gets translated in high level database
languages such as SQL
 It gets translated into expression that can be further used at
physical level of the file system

z
 After this the actual evaluation of queries and a variety of query
aa
optimising transformation takes place
 Thus before processing query a computer system needs to
Aw

translate the query into human readable and understandable


language
 SQL is best suitable choice for humans but it is not perfectly
ut

suitable for the internal representation of the query of the system


gr

 Relational algebra is well suited for through internal representation


Ja

of the query
 When a user executes any query for generation the internal form of
the query, the parser in the system checks the syntax of the query,
verifies the name of the relation in the database, tuple & finally
required attribute value

2. Optimization
 SQL is very high level languages
 The user specified what to search for now. How is search
actually done
 The algorithms are chosen automatically by DBMS
 For a given SQL query there may be many possible execution plan
 Amongst all equivalent plans choose one with lowest cost

Click :Youtube Channel | Free Material | Download App


 Cost is estimated using statistical information from the database
catalogue

3. Evaluation
 For this with addition the relational algebra translation, it is
required to annotate translated relational algebra expression with
instruction used for specify and evaluation each operation. Thus
after translating the user the system executes a query evaluation
plan
 A query evaluation plan is responsible for output of the given query

z
aa
Aw
ut
gr

Q8 (A) Explain SQL commands : COMMIT & ROLLBACK (3M)


Ja

ANS
COMMIT
 The commit command is used to save permanent any transaction to
the database
 When we perform, read or write operations to the database and
those changes can be undone by rollback operations. To make these
changes permanent we should make use of commit
 Syntax : commit ;

ROLLBACK
 The rollback command is used to undo transactions that have not
already saved to the database
 Syntax : Rollback;

Click :Youtube Channel | Free Material | Download App


Q8 (B) 4 marks

a) Print details of the Workers who are also Managers.


b) SQL query to clone a new table from another table
c) Fetch the list of employees with the same salary
d) Fetch “FIRST_NAME” from Worker table in upper case

z
ANS
aa
a) Print details of the Workers who are also Managers.
Aw

select distinct w.First_name , T.worker_title


from Worker W
Inner Join title t on w.Worker_ID = t.Worker_REF_ID
ut

Where t.Worker_Title = ‘Manager’;


gr

b) SQL query to clone a new table from another table


Ja

select * into workerclone from worker;

c) Fetch the list of employees with the same salary


SELECT distinct W.Worker_ID, W.First_name, W.salary
FROM Worker W, Worker W1
Where W.Salary = W1.salary and W.Worker_ID ! = W1.WorkerID;

d) Fetch “FIRST_NAME” from Worker table in upper case


select Upper(First name) from Worker;

Click :Youtube Channel | Free Material | Download App


Q8 (C) List techniques to obtain the query cost. Estimate any one (7M)

ANS
 There are multiple possible evaluation plan for a query and it is
important to table to compare the alternatives in terms of the
estimate cost and choose the best plan
 There are many factors that contribute to query cost
 Disk Access
 CPU time to execute the query
 Cost of communication in the distributed and parallel
database system
 The cost of access data from disk is an important cost. Normally disk
access is relatively slow as compared to in memory operations.
Moreover the CPUs speed is much faster than the disk speed. Hence

z
time spent in disk is relatively dominant factor in query execution
aa
 Computing CPU access time is comparatively harder hence we will
not consider the CPU time to execute the query
Aw
 Similarly the cost of communication does not matter for simple large
database is present in the centralised database system
ut

 Typically disk access is predominant cost & is also relatively easy to


gr

estimate working into account


Number of access × Average seek time
Ja

No of blocks read × Average block read cost


No of blocks written × Average block write cost

 Cost to write a block is greater than cost to read a block because data
is read back after being written to ensure that write successful
 We use number of block transfer from disk and number of disk seeks
to estimate query cost
Let,
b be number of blocks
s be number of seeks
tT is average time required to transfer block of data
tS is average block access time in seconds
Then query cost can be computed using following formula
b * tT + s * tS

Click :Youtube Channel | Free Material | Download App

You might also like