SUMMER 2021 Paper Solution - DBMS
SUMMER 2021 Paper Solution - DBMS
Q1 (A) What is Data Definition Language? List DDL statements & explain
anyone with example (3M)
ANS
Data Definition Language
Data Definition Language(DDL) is a specialised language used to
specify or database schema by set of definitions
It is a language which is used for creating and modifying the
structures of tables, views, index and so on
DDL is also used to specify additional properties of data
Some of the common commands used in DDL are : CREATE, ALTER &
DROP
z
CREATE
aa
CREATE TABLE statement is used to create a new table in
database
Aw
Syntax :
CREATE TABLE table_name{
column1 datatype,
ut
column2 datatype,
};
gr
Example :
Ja
ANS
ACID property of transaction
1) Atomicity
2) Consistency
3) Isolation
4) Duration
1. Atomicity
These properties states that each transactions must be
considered as a single unit and must be completed fully or not
completed at all
No transaction in the database is left half completed
z
Database should be in a state either before the transaction
aa
execution or after the transaction execution. It should not be in
state executing
Aw
2. Consistency
The database must remain in consistent state after performing
ut
any transaction
gr
3. Isolation
Ja
4. Duration
The database should be strong enough to handle any system
failure
If there is any set of insert/update, then it should be able to
handle & commit to database
If there is any failure, database should be able to recover M to
consistent state
ANS
z
B→F aa
(A)+ = {A, D, E, I, J}
(B)+ = {E, F, G, H}
Aw
R1 = {A, D, E, I}
R2 = {B, F, G, J}
ut
R3 = {A, B, C}
gr
R1 = {A, D, E, I, J}
R2 = {B, F, G, J}
R3 = {A, B, C}
(D)+ = {D, I, J}
D → IJ
T.D is present
(D)+ = {D, I, J}
R2 (B, F, G, H)
(B)+ = {B, F, G, H}
B → FGH
(F)+ = {F, G, H}
F → GH TD is present
Here B is ck & sk
R2A = (F, G, H)
R2B = (B, F)
R3 = (A, B, C)
AB → C
AB is SK
z
So R3 in 3NF aa
3NF : -
Aw
R1A = (D, I, J)
R1B = (A, E, D)
R2A = (F, G, H)
ut
R2B = (B, F)
gr
R3 = (A, B, C)
Ja
Q2 (A) Difference shared lock & exclusive locked based protocol (3M)
ANS
ANS
z
1
1
1
1
aa
Aw
ANS
gr
Ja
ANS
z
Πperson_name (Employee) aa
b) Find city of employee whose name is ‘jashu’
Aw
Πcity(σperson_name=’Jashu’ (Employee)
c) Find name and city of all employee who are having salary > 50000
ut
d) Find total salary of employees who are working for company HCL
Ja
ANS
Partially Committed
In the partially committed state, a transaction executes its final
operation, But the data is still not saved in database
In total mark calculation example, a final display if total masks step is
executed in this state
Committed
A transaction is said to be committed state if it executes all its
z
operations successfully
In this state, all effects are now permanently saved on database
aa
system
Aw
Failed State
If any of checks made by database recovery system fails, then
ut
Aborted
If any of checks fail and transaction has reached a failed state then
database recovery system will make sure that database is in its
previous transaction to bring database into consistent state
ANS
z
mapping cardinality. Here one department has one head of
department (HOD) aa
Aw
ut
entity in A
z
Many to Many Relationship aa
Many entities of A are associated with many entities of B
Aw
An entity in A is associated with many entities of B and an entity
in B is associated with many entities of A
Many to Many = Many to One + One to Many
ut
gr
Ja
ANS
Two – phase locking protocol
Two - phase locking protocol divides the execution phase of the
transaction into 3 parts
1) In the first part, when the execution of transaction starts, it
seeks permission for the lock it requires
2) In the second part, transaction acquires all the locks
3) The third phase is started as soon as transaction releases its first
lock. In third phase, transaction cannot demand any new locks,
it only releases acquired lock
z
aa
Aw
ut
z
Lock Point : at 6 aa
Aw
OR
Q3(A) What is dirty write in transaction? Explain with example (3M)
ANS
ut
gr
Dirty Write
Dirty read problem occurs when one transaction updates on item of
Ja
the database and somehow transaction fails and before data gets
rollback updated database item is accessed by another transaction.
There comes the Read – write conflict between both transaction
For example :
Consider two transaction TX & TY in below diagram performing
read/write operation on account A where available balance in
account A is $300
Time T1 T2
t1 READ(A) -
t2 A = A+ 50 -
t3 WRITE(A) -
t4 - READ(A)
t5 SERVER DOWN/
ROLLBACK
OR
Q3(B) What are importance of Primary Key & Unique Key in database?
Explain with example (4M)
z
ANS aa
Aw
Primary Key
The primary key is unique or non – null key that uniquely identifies
every record in the table or relation
ut
The primary key column cannot store duplicate value that means
primary key column values are always unique. It is also called a
gr
relationship
A primary key column of one table can be referred by a foreign key
column of another table
Example :
We have table named students with attributes such as stud_id,
roll_no, Name, Mobile or Email
Features
The primary key column cannot contain duplicate values
The primary key implements the entity of the table
A table cannot have more than one primary column
Unique Key
Unique Key is single column or combination of column in a table to
uniquely identifies database record
A unique key prevents from storing duplicate values in a column
A table can contain multiple unique key column unlike a primary key
column
This key is similar to primary key, expect that one NULL value can be
stored in the unique column. The unique is also called unique
constraint and can be referred by another table’s foreign key
Example
Let’s consider same table named students with attributes such as
z
stud_ID, Roll_No, Name, Mobile & Email aa
Aw
We can construct the unique key from one or more table fields
gr
The unique constraint column can store NULL value but only
one NULL is allowed null per column
The foreign key can reference unique constraint in preserving
uniqueness of table
OR
Q3(C) What is deadlock in transaction? How to detect deadlock in
system? Explain with example (7M)
ANS
Deadlock
A deadlock is a condition where two or more transactions are waiting
indefinitely for one another to give up locks
z
aa
Aw
Deadlock Detection
In a database, when a transaction wait to obtain a lock, then
ut
or not. Lock manager maintains the wait for graph to detect the
deadlock cycle in the details
Ja
Q4(B) What is role of an index in DBMS? Explain dense index with example
(4M)
z
ANS aa
Aw
Indexing
Indexing is used to optimise the performance of database by
minimising the number of disk access required when a query is
ut
processed
The index is a type of data structure. It is used to locate an access the
gr
Dense Index
The dense index contains an index record for every search key value
in data file. It makes search faster
In this, number of records in the index table is same as the number of
records in the main table
It needs more space to store index record itself. The index record
have the search key and point to the actual record on the table
ANS
Schedule
A series of operation from one transaction to another transaction is
known as Schedule. It is used to preserve the order of the operation
in each of the individual transaction
Conflict Serializable
The two operations become conflicting if conditions satisfy
1) Both belongs to separate transactions
2) They have the same data item
3) They contain at least one write operations
z
Example aa
Swapping is possible only if S1 and S2 are logically equal
Aw
1) T1 : Read(A) T2 : Read (A)
ut
gr
2) T1 : Read(A) T2 : Write(A)
3) T1 : Write(A) T2 : Read(A)
z
aa
Aw
ut
gr
OR
Ja
Q4(A) What is log based recovery? Listen explain various field used in log
records in for log based recovery? (3M)
ANS
ANS
z
View Serializability aa
A schedule will view serializable if it is view equivalent to serial
schedule
Aw
blind writes
gr
View Equivalence
Two schedules S1 & S2 are said to be view equivalent if they satisfy
Ja
following conditions
1) Initial Read
An initial read of both schedule must be the same
Suppose two schedule S1 & S2. In schedule S1 if a transaction
T1 is reading data, item A in S2 transaction T1 should also read
A
3) Final Write
A final write must be same between both schedules. In
schedule S1 if transaction T1 updates A at last then in S2, final
z
writes operations should also be done by T1
aa
Aw
done by T3
Ja
OR
Q4(C) Explain various steps involved in query processing with example (7M)
ANS
z
the query, the parser in the system checks the syntax of the query,
aa
verifies the name of the relation in the database, tuple & finally
required attribute value
Aw
2. Optimization
SQL is very high level languages
ut
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
ANS
SQL Injection
aa
SQL injection is the code penetration technique that might cause loss
Aw
throughout database
It is one of the most prettiest web hacking techniques to place
ut
by malicious user
A successful attack may result in the unauthorised viewing of users
Ja
ANS
Cursor
When an SQL statement is processed, oracle creates a memory area
known as context area
A cursor is a point to this context area. It contains all information
needed for processing the statement
In PL/SQL the contact area is controlled by the cursor. A cursor
contains information on a select statement and rows of data accessed
by it
A cursor is used to referred to program fetch & process row returned
by SQL statement, one at time. There are two types of cursor
1) Implicit Cursor
z
2) Explicit Cursor
Implicit Cursor
aa
The implicit cursor automatically generated by Oracle while an SQL
Aw
Example :
CURSOR cursor_name IS select_statement;
OPEN cursor_name
FETCH cursor_name INTO variable_list
CLOSE cursor_name
ANS
z
a) Give name of employees whose employee number is '001'
aa
SELECT emp-name
FROM employee
Aw
SELECT cust-name
gr
FROM deposit
WHERE branch-name LIKE 'S%';
Ja
z
In above system TS > S > C > U, where TS > S means class TS
aa
object is more sensitive than class S object.
A user can access data by following two rules :
Aw
a) Security Property :
Security Property states that subject at given security
level may not read an object at higher security level
ut
ANS
Grant
SQL grant is a command used to provide access or privileges on
database object to users
Syntax :
GRANT privilege_name
ON object_name
TO{user_name|public|rolename}
{with grant option}
Revoke
REVOKE command removes user access rights or privileges to
database objects
Syntax :
REVOKE privilege_name
z
ON object_name
FROM {user_name|public|role_name}
aa
Aw
OR Q5(C) Write PL/SQL program that fetches records as students having CPI
> 4 in ELIGIBLE table & students having CPI < = 4 in NOT_ELIGIBLE table from
ut
ANS
Ja
Declare
create table eligible{
studID int;
stud_name varchar(255);
sem varchar(10);
CPI int;
}
create table not_eligible{
studID int;
stud_name varchar(255);
sem varchar(10);
CPI int;
}
CPI integers
z
aa
Aw
ut
gr
Ja