Winter 2020 Paper Solution - Dbms
Winter 2020 Paper Solution - Dbms
z
data and various programmes that are used to handle that data
ANS
Ja
Q1 (C) Difference between Strong Entity Set & Weak Entity Set.
Demonstrate concept of both using real – time example using E – R
diagram (7M)
ANS
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
Strong Entity
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
{EFH}+ = {E, F, H}
Ja
Functional Dependencies
A → B, BC → D, E → C, D → A
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
{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
ANS
z
aa
Aw
ut
gr
Ja
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
ANS
Inputs :
ΠEmp_name, salary (Employee ⋈ Salary)
Output :
Emp_name Salary
z
Stephan 50000 aa
Jack 30000
Aw
Harry 25000
Outer Join
ut
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
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
ProductName
Chais
Chang
Aniseed syrup
Mishi Kobe
z
Group by orderID having max(Quantity) > All
aa
(select avg(Quantity) from orderdetails Group by OrderID);
Aw
Output :
Order ID
10248
ut
gr
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 :
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
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)
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
a) Get the details about all flights from Chennai to New Delhi
Ja
ANS
a) Get the details about all flights from Chennai to New Delhi
σsrc=”Cheenai” ^ dest = “New Delhi” (flight)
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
4) Durability
gr
ANS
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 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
ANS
z
1) T1 : Read(A) T2 : Read (A)
aa
Aw
2) T1 : Read(A) T2 : Write(A)
Ja
3) T1 : Write(A) T2 : Read(A)
z
aa
Aw
operations
Ja
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
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
z
4) File : a file is a collection of related record. Example : An
aa
employee file world contains records of employees of firms
Aw
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
z
aa
Q7(A) Explain following SQL command : GRANT & REVOKE (3M)
Aw
ANS
ut
Grant
gr
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
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
ANS
Ja
b) Print details of Workers whose SALARY lies between 10000 & 50,000
SELECT * FROM Worker
WHERE SALARY BETWEEN 100000 AND 500000;
ANS
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
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
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
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;
z
ANS
aa
a) Print details of the Workers who are also Managers.
Aw
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
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