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

University Solution 2021-22 Dbms (1)

The document outlines the structure and content of a B. Tech. examination paper for Database Management Systems, including various sections with questions on topics such as physical data independence, functions of a DBA, relational calculus, and ACID properties of transactions. It provides detailed answers to questions related to database concepts, operations, and models, emphasizing the importance of data integrity, security, and concurrency control. The examination aims to assess students' understanding of key database principles and their practical applications.

Uploaded by

vibhavbhartiya13
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)
16 views

University Solution 2021-22 Dbms (1)

The document outlines the structure and content of a B. Tech. examination paper for Database Management Systems, including various sections with questions on topics such as physical data independence, functions of a DBA, relational calculus, and ACID properties of transactions. It provides detailed answers to questions related to database concepts, operations, and models, emphasizing the importance of data integrity, security, and concurrency control. The examination aims to assess students' understanding of key database principles and their practical applications.

Uploaded by

vibhavbhartiya13
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/ 22

Printed Pages: Sub Code: KCS 501

Paper Id: Roll No.

B. TECH.
(SEM V) THEORY EXAMINATION 2021-22
DATABASE MANAGEMENT SYSTEM
Time: 3 Hours Total Marks: 100
Note: 1. Attempt all Sections. If require any missing data; then choose suitably.
2. Any special paper specific instruction.

SECTION A

1. Attempt all questions in brief. 2 x 10 = 20


a. What is the significance of Physical Data Independence?

Ans: It is the ability to change the internal schema definition without affecting
the conceptual or external schema. An internal schema may be changed due to
several reasons such as for creating additional access structure, changing the
storage structure, etc. The separation of internal schema from the conceptual
schema facilitates physical data independence.
b. List the four functions of DBA.
Ans:
1. Software installation and Maintenance
2. Data Extraction, Transformation, and Loading
3. Database Backup and Recovery
4. Security
it is a technical person or technician responsible for implementing the data
administrator’s decisions.

c. When a relation set is called a recursive relationship set?


Ans; When an Entity is related with itself it is known as Recursive
Relationship.
d. What do you mean by currency with respect to database?
Ans: accurate, up to date information is available on demand at any time.

e. What is Relational Calculus?


Ans: Relational Calculus is a non-procedural query language, that is, it tells
what to do but never explains how to do it.

f. What is Equi-Join in database?


Ans: A⋈cB: It is the special case of theta join. It is based on equality condition
(common values) on un-common attributes.

g. What is a CLAUSE in terms of SQL?


Ans: Clauses are in-built functions available to us in SQL. With the help of
clauses, we can deal with data easily stored in the table. When we have large
amounts of data stored in the database, we use Clauses to query and get data
required by the user.
h. Define the closure of an attribute set.
Ans: The closure of a set of attributes X is the set of those attributes that can
be functionally determined from X. The closure of X is denoted as X+. When
given a closure problem, you'll have a set of functional dependencies over
which to compute the closure and the set X for which to find the closure.
i. When is a transaction Rolled Back?
Ans: Rolls back an explicit or implicit transaction to the beginning of the
transaction, or to a savepoint inside the transaction. You can use ROLLBACK
TRANSACTION to erase all data modifications made from the start of the
transaction or to a savepoint. It also frees resources held by the transaction.
Restore database to original since the last COMMIT
j. List the various levels of locking?
Ans: Locks can be of several levels. The level of a lock refers to the scope of
the resource on which the lock is requested or used, for example, whether the
lock affects:
•A single row
•A single page
•A table as a whole
•An entire database
Row, page, and table lock levels are subject to user control, whereas
database and table "control" locks are taken by commands and utilities
(such as the SQL statement MODIFY utility).

SECTION B

2. Attempt any three of the following: 10 x 3 = 30


a. Draw the overall structure of DBMS and explain its various components.
Ans: A database management system is a piece of software that provides services
for accessing a database, while maintain all the required features of the data.
Commercially available Database management systems in the market are dbase,
FoxPro, IMS and Oracle.
These systems allow users to create, update, and extract information from their
database. Compared to a manual filing system, the biggest advantages to a
computerized database system are speed, accuracy and accessibility.

General view of DBMS:

Related
User query DD/D subsystem to
DD/
facility or “form” D

Security and Integrity


subsystem
Application Related
to
Program Database Access
DB
Development subsystem

DBMS provides different services to the users:

1. A centralized data definition and data control facility or data dictionary/


directory (DD/D): it can be assumed or viewed as being a part of database itself.
Directory contains definitions of all data items in the database. This includes
elementary level data items (fields), files or relational tables).
It means a place where we are storing our whole database can be assumed as data
dictionary containing all information about database. The information in DD/D is
called metadata that is “data about data”. Meta data means data in DD which
describes database.
2. Data security and integrity:
Data security (to protect our data by un-authorized user) is the full access to the
authorized user. Users are allowed to all those things which he is trying to do.
Database is a valuable resource needing protection. We can protect the database
by giving a password. Limiting the access of database by the authorized user.
Data integrity ensures that the things we are trying to do are correct.
3. Concurrent data access for multiple users: DBMS typically allows many
transactions to access the same data at the same time. One of the important
functions of DBMS is to support the access, retrieval, and update the data in
database. The centralization of the data in a database increases the probability that
two or more users will want to access the same data at same time. If DBMS allows
this, the two users would certainly affect each other’s work and could damage it.
So it is important that DBMS protect the data by other users. To do this DBMS
uses the locking mechanism to protect the data.
4. user-oriented data query, manipulations, and reporting capabilities.
5. programmer-oriented applications system development facilities: DBMS
provides tools such as screen, menu, report, generator, translators, compilers and
data & view definition facilities to the application programmer.

b. Which relational algebra operations require the participating tables to be union-


compatible? Give the Reason in detail.
Ans: Union, Intersection and difference are required to be union compatible in
participating table.
The relations in union, intersection and difference operations are union
compatible. Two relations P(p) and Q(q) are said to be union compatible if both
P and Q are of the same degree n and domains of the corresponding n attributes
are identical i.e. if P- {p1, p2, p3,.......pn} and Q= { q1, q2,.....qn} then domain
(pi) = domain (qi) for i=1,2,3....n where domain(pi) represents the domain of the
attribute pi.

P(p): this P table is for project a1


ID Name
01 x
02 y
03 z
04 a
05 b

Q(q): this Q table is for project a2


ID Name
01 x
02 y
05 b
07 c
09 d

It is an example of employee of relation P(p) and Q(q) that are working on two
projects a1 and a2 respectively.
Different operations can be performed on these tables,
1. there are no. of persons that are working on both projects a1 and a2.

R(R): P(p) U Q(q)


ID Name
01 x
02 y
03 z
04 a
05 b
07 c
09 d

2. (a) the persons that are working in only relation P(P).

R(R): P(p) - Q(q)

ID Name
03 z
04 a

2. (b) the persons that are working in only relation Q(Q).

R(R): Q(q) - P(p)


ID Name
07 c
09 d

3. The persons those are common in both relations,


R(R): P(p) ∩ Q(q)
ID Name
01 x
02 y
05 b

When we are applying the union operations to the relations we must remember
that the both relations should be in union compatible. If we want to Apply these
three operators on two relations that are not union compatible, then we can use
rename operator to make them union compatible first before performing the desire
operation.

c. What do you understand by transitive dependencies? Explain with an example


any two problems that can arise in the database if transitive dependencies are
present in the database.
Ans: Transitive dependency is allowed in 2NF. It is due to the
dependency between non key or non-prime attributes.

x y
y z, here z is dependent on y as well as x by transitivity rule x z. x is only
the prime key attribute but y and z are non-key attributes.

A transitive dependency in a database is an indirect relationship between values


in the same table that causes a functional dependency.

To achieve the normalization standard of Third Normal Form (3NF), you must
eliminate any transitive dependency.

Example
<MovieListing>

Movie_ID Listing_ID Listing_Type DVD_Price ($)

M08 L09 Crime 180

M03 L05 Drama 250

M05 L09 Crime 180

The above table is not in 3NF because it has a transitive functional dependency

Movie_ID -> Listing_ID


Listing_ID -> Listing_Type

Therefore, the following has transitive functional dependency.

Movie_ID -> Listing_Type

The above states the relation <MovieListing> violates the 3rd Normal Form
(3NF).

To remove the violation, you need to split the tables and remove the transitive
functional dependency.

<Movie>

Movie_ID Listing_ID DVD_Price


($)
M08 L09 180
M03 L05 250
M05 L09 180

<Listing>

Listing_ID Listing_Type
L09 Crime
L05 Drama
L09 Crime

By its nature, a transitive dependency requires three or more attributes (or


database columns) that have a functional dependency between them, meaning
that Column A in a table relies on Column B through an intermediate Column
C.
d. List ACID properties of transaction. Explain the usefulness of each. What is the
importance of log?
Ans: The acronym ACID is sometimes used to refer above four properties of
transaction that we have presented here: Atomicity, Consistency, Isolation, and
Durability.
There are four important properties of transaction that a DBMS must ensure to
maintain data in the case of concurrent access and system failures. These are:
Atomicity: (all or nothing)
A transaction is said to be atomic if a transaction always executes all its actions
in one step or not executes any actions at all It means either all or none of the
transactions operations are performed.
Consistency: (No violation of integrity constraints)
A transaction must preserve the consistency of a database after the execution. The
DBMS assumes that this property holds for each transaction. Ensuring this
property of a transaction is the responsibility of the user. Log makes it possible.
Log runs in parallel with actions simultaneously.
Isolation: (concurrent changes invisibles)
Data can be fetched concurrently, but cannot be changed concurrently. It must be
in sequence. The transactions must behave as if they are executed in isolation. It
means that if several transactions are executed concurrently the results must be
same as if they were executed serially in some order. The data used during the
execution of a transaction cannot be used by a second transaction until the first
one is completed.
Durability: (committed update persist)
The effect of completed or committed transactions should persist even after a
crash. It means once a transaction commits, the system must guarantee that the
result of its operations will never be lost, in spite of subsequent failures.
Log is a sequence of records, which maintains the records of actions performed
by a transaction. It is important that the logs are written prior to the actual
modification and stored on a stable storage media, which is failsafe.
In order to maintain atomicity of transaction, the database system (log) keeps
track of the old values of any write and if the transaction does not complete its
execution, the old values are restored to make it appear as the transaction never
executed. The rollback and commit operation are the key to way it works.

e. What do you mean by time stamping protocol for concurrency controlling?


Discuss multi version scheme of concurrency control.
Ans: Timestamp Ordering Protocol
The timestamp-ordering protocol ensures serializability among transactions in their
conflicting read and write operations. This is the responsibility of the protocol system
that the conflicting pair of tasks should be executed according to the timestamp values
of the transactions.

A timestamp is a tag that can be attached to any transaction or any data item, which
denotes a specific time on which the transaction or the data item had been used in any
way. A timestamp can be implemented in 2 ways. One is to directly assign the current
value of the clock to the transaction or data item. The other is to attach the value of a
logical counter that keeps increment as new timestamps are required.

The timestamp of a data item can be of 2 types:

(i) W-timestamp(X):

This means the latest time when the data item X has been written into.

(ii) R-timestamp(X):

This means the latest time when the data item X has been read from. These 2 timestamps
are updated each time a successful read/write operation is performed on the data item
X.

 The timestamp of transaction Ti is denoted as TS(Ti).


 Read time-stamp of data-item X is denoted by R-timestamp(X).
 Write time-stamp of data-item X is denoted by W-timestamp(X).
Timestamp ordering protocol works as follows −
 If a transaction Ti issues a read(X) operation −
o If TS(Ti) < W-timestamp(X)
 Operation rejected.
o If TS(Ti) >= W-timestamp(X)
 Operation executed.
o All data-item timestamps updated.
 If a transaction Ti issues a write(X) operation −
o If TS(Ti) < R-timestamp(X)
 Operation rejected.
o If TS(Ti) < W-timestamp(X)
 Operation rejected and Ti rolled back.
o Otherwise, operation executed.

Multiversion Concurrency Control: Multiversion schemes keep old versions of


data item to increase concurrency.
Multiversion 2 phase locking: Each successful write results in the creation of a
new version of the data item written. Timestamps are used to label the versions.
When a read(X) operation is issued, select an appropriate version of X based on
the timestamp of the transaction.
SECTION C
3. Attempt any one part of the following: 10 x 1 = 10
(a) What are the different types of Data Models in DBMS? Explain them.
Ans: Data Models

Structured design of a complex system. A simplified representation used to explain


the working of a real world system or event. Date models show, how to organize or
structure data. Data models are the representation of reality that retains only the
selected details. Data Model can be defined as an integrated collection of concepts
for describing and manipulating data, defining relationships between data, and
constraints on the data in an organization.
A Database model defines the logical (non-physical yet underpinned by something
physical or actual, reasonable) design of data. The model describes the relationships
between different parts of the data.

A data model comprises of three components:

1. A structural part, consisting of a set of rules according to which databases can


be constructed. Order of data (i.e., name of attrib., type, size etc.)

2. A manipulative part, defining the types of operation that are allowed on the data
(this includes the operations that are used for updating or retrieving data from the
database and for changing the structure of the database). (Selection, insertion,
deletion, updation)

3. Possibly a set of integrity rules, which ensures that the data is accurate. (check,
null, not null, key etc.)

The purpose of a data model is to represent data and to make the data
understandable. There have been many data models proposed in the literature. They
fall into three broad categories:

 Physical Data Models


 Record Based Data Models
 Object Based Data Models

The object based and record based data models are used to describe data at the
conceptual and external levels, the physical data model is used to· describe data at
the internal level.

Physical Data Models

Physical data models describe how data is stored in the computer, representing
information such as record structures, record ordering, and access paths. There are
not as many physical data models as logical data models, the most common one
being the Unifying Model (promoting unity, It defines data architecture that is
necessarily rooted in actual digital hardware that can encompass every data
relationship).

This unifying model may be comprising of NTFS (New Technology file system,
new version) and FAT32 (file allocation table, old version). Actual H/W circuitry
and functionality of components are discussed in such kind of models.

Record (set of attributes) Based Logical Models

Record based logical models are used in describing data at the logical and view
levels. In contrast to object based data models, they are used to specify the overall
logical structure of the database and to provide a higher-level description of the
implementation. Record based models are so named because the database is
structured in fixed format records of several types. Each record type defines a fixed
number of fields, or attributes, and each field is usually of a fixed length. The three
most widely accepted record based data models are:

• Hierarchical Model
• Network Model
• Relational Model

The relational model has gained favor over the other two in recent years. The
network and hierarchical models are still used in a large number of older databases.
Hierarchical Data Model
It was used to define the file system arrangements within a computer. In this model
each entity has only one parent but can have several children. At the top of hierarchy
there is only one entity which is called Root.
A large number of computer systems have been written that use this structure.
Unlike families in real life, a parent in a hierarchical database may have more than
one child, but a child always has only one parent. To find a particular record, you
have to start at the top with a parent and trace it down the chart to that child. It is
used in some reservation systems. Accessing or updating data is very fast because
the relationships have been predefined. The problem is that there are no
relationships among the child records.

The hierarchical data model is the oldest type of data model, developed by IBM in
1968. This data model organizes the data in a tree-like structure (tree is a
connected graph having no loop), in which each child node (also known as
dependents) can have only one parent node. The database based on the
hierarchical data model comprises a set of records connected to one another through
links. The link is an association between two or more records. The top of the tree
structure consists of a single node that does not have any parent and is called the
root node.

The root may have any number of dependents; each of these dependents may have
any number of lower level dependents. Each child node can have only one parent
node and a parent node can have any number of (many) child nodes. It, therefore,
represents only one-to-one and one-to-many relationships. The collection of same
type of records is known as a record type.

The main advantage of the hierarchical data model is that the data access is quite
predictable in the structure and, therefore, both the retrieval and updates can be
highly optimized by the DBMS.

However, the main drawback of this model is that the links are ‘hard coded’ into
the data structure, that is, the link is permanently established and cannot be
modified. The hard coding makes the hierarchical model rigid. In addition, the
physical links make it difficult to expand or modify the database and the changes
require substantial redesigning efforts.

These are the 1: N mapping between record types. This is done by using the
tree concept. It restricts only child segment to have only one parent segment.
Fig: Hierarchical Model

Figure shows the hierarchical model of Doctor’s Patient database. It consists of two
record types, namely, Physician number and Physician Name. For simplicity,
only few fields of each record type are shown. One complete record of each record
type represents a node.

Network Data Model

It was used to define the network structure among the computers. In the network
model, entities are organized in a graph, in which some entities can be accessed
through several paths. Data in such type of model are represented by collection of
records and relationships between the records of two tables are represented by links
usually called as pointer.

It is similar to the hierarchical model, but each child record can have more than one
parent record. Thus a child record, in network terminology called a member, may
be reached through more than one parent, called owners.

The first specification of network data model was presented by Conference on Data
Systems Languages (CODASYL) in 1969, followed by the second specification in
1971. It is powerful but complicated. In a network model the data is also represented
by a collection of records, and relationships among data are represented by links.
However, the link in a network data model represents an association between
precisely two records. Like hierarchical data model, each record of a particular
record type represents a node. However, unlike hierarchical data model, all the
nodes are linked to each other without any hierarchy. The main difference between
hierarchical and network data model is that in hierarchical data model, the data is
organized in the form of trees and in network data model, the data is organized in
the form of graphs.

The main advantage of network data model is that a parent node can have many
child nodes and a child can also have many parent nodes. Thus, the network model
permits the modeling of many-to-many relationships in data.

The main limitation of the network data model is that it can be quite complicated
to maintain all the links and a single broken link can lead to problems in the
database. In addition, since there are no restrictions on the number of relationships,
the database design can become complex. Figure below shows the network model
of Online Book database.

Fig: Network Model

The popularity of the network data model coincided with the popularity of the
hierarchical data model. Some data were more naturally modelled with more than
one parent per child. So, the network model permitted the modelling of many-to-
many relationships in data. The basic data modelling construct in the network model
is the set construct. A set consists of an owner record type, a set name, and a member
record type.

Relational Model

In this model, data is organised in two-dimensional tables called relations. The


tables or relation are related to each other. A relation is visualized as named table.
Each column or field of the table corresponds to an attribute of relation and its name.
Row or records of the relation are referred to as tuples of the relation and columns
are attributes. Each attribute has a distinct name. Values in each attribute are in a set
called domain. In relational model. No two rows are identical. It is record based
logical model that is used to describe the data at the logical and view levels.
Record- and table-based model Relational database modeling is a logical-level
model and it is proposed by E.F. Codd, which is
 Based on mathematical relations
 Uses relations, represented as tables
 Columns of tables represent attributes
 Tables represent relationships as well as entities
Successor to earlier record-based models—network and hierarchical

Fig: Relational Model

Object Based Data Models

Object based data models use concepts such as entities, attributes, and relationships.
An entity is a distinct object (a person, place, concept, and event) in the organization
that is to be represented in the database. An attribute is a property that describes
some aspect of the object that we wish to record, and a relationship is an association
between entities. Some of the more common types of object based data model are:

• Object Oriented • Entity-Relationship

The Entity-Relationship model has emerged as one of the main techniques for
modeling database design and forms the basis for the database design methodology.

The object oriented data model extends the definition of an entity to include, not
only the attributes that describe the state of the object but also the actions that are
associated with the object, that is, its behaviour.

The object is said to encapsulate both state and behavior. Entities in semantic
systems represent the equivalent of a record in a relational system or an object in an
OO system but they do not include behavior (methods). They are abstractions 'used
to represent real world (e.g. customer) or conceptual (e.g. bank account) objects.
The functional data model is now almost twenty years old. The original idea was to'
view the database as a collection of extensionally defined functions and to use a
functional language for querying the database.

Object-oriented Model

Uses the E-R modeling as a basis but extended to include encapsulation,


inheritance. Objects have both state and behavior.
 State is defined by attributes
 Behavior is defined by methods (functions or procedures)
Designer defines classes with attributes, methods, and relationships. Class
constructor method creates object instances
 Each object has a unique object ID
 Classes related by class hierarchies
 Database objects have persistence

Fig: Object Model

Entity-Relationship Model

It is graphical, diagrammatic, pictorial representation of data. Relational model is


based upon Entity-Relationship Model which is a semantic model; E-R modelling
is a conceptual level model which was proposed by P.P. Chen in 1970s. It describes
the data which are on logical level and view level. It describes the data in database
and relationship among them not the methods of representing the data fields.

 captures mean Adds new complex datatypes to relational model


 Adds objects with attributes and methods
 Adds inheritance
 SQL extended to handle objects in SQL:1999

(b) State the procedural DML and nonprocedural DML with their differences.
Ans:
Database languages:

Language is the medium to express our view. Programming languages are based on
syntax (grammar which is the concern of compiler or interpreter itself) and
semantics (logic which is the concern of developer). The main objective of a
database management system is to allow its users to perform a number of operations
on the database such as insert, delete, and retrieve data in abstract terms without
knowing about the physical representations of data. To provide the various facilities
to different types of users, a DBMS normally provides one or more specialized
programming languages called Database (or DBMS) Languages.

Data Definition Language:

It defines/ describes the definition of database schema or any table in the form that
can be linked or that can be acceptable by the data manipulation language or that
can be accepted by application a program which is written for the operations to be
performed on that table (which is included in the application program in the form of
schema portion of database).

Or we can say that it is the language used to specify the database schema. The result
of compilation or collection of DDL statements is a set of tables that is stored in a
special file called data dictionary (it is a file that contains the metadata).

In DBMSs where no strict separation between the levels of the database is


maintained, the data definition language is used to define the conceptual and internal
schemas for the database. On the other hand, in DBMSs, where a clear separation is
maintained between the conceptual and internal levels, the DDL is used to specify
the conceptual schema only.

The DDL statements are also used to specify the integrity rules (constraints) in order
to maintain the integrity of the database. The various integrity constraints are
domain constraints, referential integrity, assertions and authorization. These
constraints are discussed in detail in subsequent chapters. Like any other
programming language, DDL also accepts input in the form of instructions
(statements) and generates the description of schema as output. The output is placed
in the data dictionary, which is a special type of table containing metadata. The
DBMS refers the data dictionary before reading or modifying the data. Note that the
database users cannot update the data dictionary; instead it is only modified by
database system itself.

Some of the examples are:

 CREATE - to create objects in the database


 ALTER - alters the structure of the database or used to add, delete,
or modify columns in an existing table
 DROP - delete objects from the database or deletes a table in the
database
 TRUNCATE –command deletes the data inside a table, but not the
table
 COMMENT - add comments to the data dictionary
 RENAME - rename an object

Data Manipulation Language


Once the database schemas are defined and the initial data is loaded into the
database, several operations such as retrieval, insertion, deletion, and modification
can be applied to the database. The DBMS provides data manipulation language
(DML) that enables users to retrieve and manipulate the data. The statement which
is used to retrieve the information is called a query. The part of the DML used to
retrieve the information is called a query language. However, query language and
DML are used synonymously though technically incorrect.

The DML are of two types, namely, non-procedural DML and procedural DML.

The non-procedural or high-level or declarative DML enables to specify the


complex database operations concisely. It requires a user to specify what data is
required without specifying how to retrieve the required data. For example, SQL
(Structured Query Language) is a non-procedural query language as it enables user
to easily define the structure or modify the data in the database without specifying
the details of how to manipulate the database. The high-level DML statements can
either be entered interactively or embedded in a general purpose programming
language. It provides the facilities for stating what is desired rather than how to get
it.

On the other hand, the procedural or low-level DML requires user to specify what
data is required and how to access that data by providing step-by-step procedure to
solve a problem. For example, pascal, PLSQL and relational algebra, DL/1 is
procedural query language, which consists of set of operations such as select,
project, union, etc., to manipulate the data in the database. \

The fundamental unit of procedural programming is an action which is further


divided into three parts – computational actions (for example arithmetic operations),
control-flow actions (like comparison and looping statements), and input-output
actions (such as read and write operations). So, here the primary concept is the
machine state, which is the group of all values for all memory locations in the
computer.

The major difference between these computational models is that the procedural
language is command-driven whereas non-procedural language is function oriented.

Some of the examples are:


 SELECT - Retrieve data from the a database
 INSERT - Insert data into a table
 UPDATE - Updates existing data within a table
 DELETE - deletes all records from a table, the space for the records remain
 MERGE - UPSERT operation (insert or update)
 CALL - Call a PL/SQL or Java subprogram
 EXPLAIN PLAN - explain access path to data
 LOCK TABLE - control concurrency

Data Control Language (DCL) The DCL statements are,

 GRANT - gives user's access privileges to database


 REVOKE - withdraw access privileges given with the GRANT command
Transaction Control Language (TCL)
Transaction Control (TCL) statements are used to manage the changes made by
DML statements. It allows statements to be grouped together into logical
transactions.

Some of the examples are:


 COMMIT - save work done
 SAVEPOINT - identify a point in a transaction to which you can later roll
back
 ROLLBACK - restore database to original since the last COMMIT
 SET TRANSACTION - Change transaction options like isolation level and
what rollback segment to use

4. Attempt any one part of the following: 10 x 1 = 10


(a) Consider the following schema for institute library:

Student (RollNo, Name, Father_ Name, Branch)

Book (ISBN, Title, Author, Publisher)

Issue (RollNo, ISBN, Date-of –Issue)

Write the following queries in SQL and relational algebra:

I. List roll number and name of all students of the branch ‘CSE’.

II. Find the name of student who has issued a book published by ‘ABC’

publisher.

III. List title of all books and their authors issued to a student ‘RAM’.

IV. List title of all books issued on or before December 1, 2020.

V. List all books published by publisher ‘ABC’.


Ans:
I. Select RollNo, Name from Student where Branch="CSE";

II. select Name from Student join Issue on Student.Roll_No = Issue.Roll_No


join Book on Issue.ISBN = Book.ISBN where Publisher ="ABC";

III. select Auther, Title from Student


join Issue on Student.Roll_No = Issue.Roll_No join Book on Issue.ISBN =
Book.ISBN where Name ="RAM";

IV. select Title from Book join Issue on Issue.ISBN = Book.ISBN where
date-of-issue >="December 1, 2020";

V. select Title from Book where Publisher ="ABC"

(b) What do you mean by trigger? Explain it by a suitable example.


Ans: Triggers are the SQL codes that are automatically executed in response to
certain events on a particular table. These are used to maintain the integrity of
the data. A trigger in SQL works similar to a real-world trigger. For example,
when the gun trigger is pulled a bullet is fired.
Syntax and Example

Let’s now look at the syntax of a trigger.

Create Trigger Trigger_Name


(Before | After) [ Insert | Update | Delete]
on [Table_Name]
[ for each row | for each column ]
[ trigger_body ]

 CreateTrigger
These two keywords are used to specify that a trigger block is going to be declared.
 Trigger_Name
It specifies the name of the trigger. Trigger name has to be unique and shouldn’t repeat.
 ( Before|After )
This specifies when the trigger will be executed. It tells us the time at which the trigger
is initiated, i.e, either before the ongoing event or after.

 Before Triggers are used to update or validate record values before they’re saved to the
database.
 After Triggers are used to access field values that are set by the system and to effect
changes in other records. The records that activate the after trigger are read-only. We
cannot use After trigger if we want to update a record because it will lead to read-only
error.
 [ Insert|Update|Delete ]
These are the DML operations and we can use either of them in a given trigger.
 on [ Table_Name ]
We need to mention the table name on which the trigger is being applied. Don’t forget
to use on keyword and also make sure the selected table is present in the database.
 [ for each row | for each column ]
o Row-level trigger gets executed before or after any column value of a
row changes
o Column Level Trigger gets executed before or after the specified
column changes

 [ trigger_body]
It consists of queries that need to be executed when the trigger is called.

5. Attempt any one part of the following: 10 x 1 = 10


(a) Describe Armstrong’s axioms in detail. What is the role of these rules in
database development process?
Ans: Armstrong's Axioms or inference rules
Armstrong's Axioms are a set of rules, that when applied repeatedly, generates
a closure of functional dependencies and check the truth of dependencies to
make dependencies irreducible. Armstrong's axioms are used to conclude
functional dependencies on a relational database. The inference rule is a type
of assertion. It can apply to a set of FD (functional dependency) to derive other
FD. Using the inference rule, we can derive additional functional dependency
from the initial set.
 Reflexivity rule − If alpha is a set of attributes and beta is subset of
alpha, then alpha holds beta.
o If B is the subset of A then A → B

 Augmentation rule − If a → b holds and y is attribute set, then


ay → by also holds. That is adding attributes in dependencies, does
not change the basic dependencies.
o If A → B then AC → BC

 Transitivity rule − Same as transitive rule in algebra, if a → b holds


and b → c holds, then a → c also holds. a → b is called as a
functionally that determines b.
o If A → B and B → C then A → C
 Decomposition rule – if A → BC then A → B and A → C
 Union rule- if A → B and A → C then A → BC
 Composition- if A → B and C → D then AC → BD
 Self Determination- A → A

(b) Describe the term MVD in the context of DBMS by giving an example. Discuss
4NF and 5NF also.
Ans: Multivalued dependency occurs when there are more than
one independent multivalued attributes in a table. two attributes (or columns)
in a table are independent of one another, but both depend on a third attribute.
If two or more independent relations are kept in a single relation (Cartesian
Product), then Multivalued Dependency is possible.
A relation should have 3 columns to have MVD with 3 conditions to satisfy,
1. A->>B, for a single value of A, more than one value exist in B.
2. Table should have at least 3 columns.
3. For this table with columns A,B,C; B and C should be independent.

Multivalued dependency can exist with more one column too, A->>B, and A-
>> C. A->>B, means A multidetermines B, or B is multidependent on A.

Fourth Normal Form: Any relation will be in 4NF if it is in BCNF and it contains
no multivalued dependency.
Example:
Enrolment Table:
St_Id Course Hobby
1 Science Cricket
1 maths Hockey
2 C# Cricket
2 Php Hockey
This above arrangement could lead to the problem.
St_Id Course Hobby
1 Science Cricket
1 maths Hockey
These two rows of data will virtually give rise to two more additional rows, that
is, science with hockey and maths with cricket.
St_Id Course Hobby
1 Science Cricket
1 maths Hockey
1 Science Hockey
1 maths Cricket
Isn’t that right. There is no relationship between course and hobby of student.
That’s why values can be interchanged with respect to science and maths of st_id
1.
So above condition occurs due bad designing practice. This problem can be
eliminated by keep such attributes in separate/independent relations.
It can be decomposed into course and hobby relations to avoid the MVD and
satisfy the 4NF.
Course:
St_Id Course
1 Science
1 maths
2 C#
2 Php
Hobby:
St_Id Hobby
1 Cricket
1 Hockey
2 Cricket
2 Hockey
Fifth normal form (5NF): A relation is in 5NF if it is in 4NF and not contains any
join dependency and joining should be lossless. 5NF is satisfied when all the
tables are broken into as many tables as possible in order to avoid redundancy.
5NF is also known as Project-join normal form (PJ/NF).
6. Attempt any one part of the following: 10 x 1 = 10
(a) Describe serializable schedule. Discuss conflict serializability with suitable
example.

Ans: A schedule is a process of grouping the transactions into one and


executing them in a predefined order. A schedule is required in a database
because when some transactions execute in parallel, they may affect the result
of the transaction – means if one transaction is updating the values which the
other transaction is accessing, then the order of these two transactions will
change the result of second transaction. Hence a schedule is created to execute
the transactions. A schedule is called serial schedule, if the transactions in the
schedule are defined to execute one after the other. A transaction is said to be
Serializable if it is equivalent to serial schedule.
Conflict Serializable: A schedule is called conflict serializable if it can be
transformed into a serial schedule by swapping non-conflicting operations.

A transaction is said to be non-conflicting, if interchanging the non-conflicting


instruction in a transaction does not change the result.

Conflicting operations: Two operations are said to be conflicting if all


conditions satisfy:

• They belong to different transaction


• They operation on same data item
• At Least one of them is a write operation

(b) Discuss the procedure of deadlock detection and recovery in transaction?


Ans: Deadlock Detection :

1. If resources have a single instance –


In this case for Deadlock detection, we can run an algorithm to check for the
cycle in the Resource Allocation Graph. The presence of a cycle in the graph
is a sufficient condition for deadlock.
2. If there are multiple instances of resources –
Detection of the cycle is necessary but not sufficient condition for deadlock
detection, in this case, the system may or may not be in deadlock varies
according to different situations.
Deadlock Recovery :
A traditional operating system such as Windows doesn’t deal with deadlock
recovery as it is a time and space-consuming process. Real-time operating
systems use Deadlock recovery.
1. Killing the process –
Killing all the processes involved in the deadlock. Killing process one
by one. After killing each process check for deadlock again keep
repeating the process till the system recovers from deadlock. Killing all
the processes one by one helps a system to break circular wait condition.
2. Resource Preemption –
Resources are preempted from the processes involved in the deadlock,
preempted resources are allocated to other processes so that there is a
possibility of recovering the system from deadlock. In this case, the
system goes into starvation.

7. Attempt any one part of the following: 10 x 1 = 10


(a) Given a schedule S for transactions T1 and T2 with set of read and write
operations,
S: R1(X) R2(X) R2(Y) W2(Y) R1(Y) W1(X).
Identify, whether given schedule is equivalent to serial schedule or not?
Ans: Two transactions of given schedules are:
T1: R1(X) R1(Y) W1(X)
T2: R2(X) R2(Y) W2(Y)
Let us first check serializability of S: R1(X) R2(X) R2(Y) W2(Y) R1(Y)
W1(X).
To convert it to a serial schedule, we have to swap non-conflicting operations
so that S becomes equivalent to serial schedule T1->T2 or T2->T1.
• S: R1(X) R2(X) R2(Y) W2(Y) R1(Y) W1(X)
• Swapping non conflicting operations R1(X) and R2(X) of S, we get
S’: R2(X) R1(X) R2(Y) W2(Y) R1(Y) W1(X)
• Again, swapping non conflicting operations R1(X) and R2(Y) of S’, we
get
S’’: R2(X) R2(Y) R1(X) W2(Y) R1(Y) W1(X)
• Again, swapping non conflicting operations R1(X) and W2(Y) of S’’,
we get
S’’’: R2(X) R2(Y) W2(Y) R1(X) R1(Y) W1(X)
• S is conflict serializable, which is equivalent to a serial schedule T2-
>T1.

(b) Discuss 2 phase commit protocol and time stamp based protocol with suitable
example. How the validation based protocols differ from 2PC?
Ans: Two-Phase Locking: This locking protocol divides the execution phase
of a transaction into three parts. In the first part, when the transaction starts
executing, it seeks permission for the locks it requires. The second part is where
the transaction acquires all the locks. As soon as the transaction releases its first
lock, the third phase starts. In this phase, the transaction cannot demand any
new locks; it only releases the acquired locks.

Timestamp-based Protocols
The most commonly used concurrency protocol is the timestamp based
protocol. This protocol uses either system time or logical counter as a
timestamp.
Lock-based protocols manage the order between the conflicting pairs among
transactions at the time of execution, whereas timestamp-based protocols start
working as soon as a transaction is created.
Every transaction has a timestamp associated with it, and the ordering is
determined by the age of the transaction. A transaction created at 0002 clock
time would be older than all other transactions that come after it. For example,
any transaction 'y' entering the system at 0004 is two seconds younger and the
priority would be given to the older one.
In addition, every data item is given the latest read and write-timestamp. This
lets the system know when the last ‘read and write’ operation was performed on
the data item.
Validation Based Protocol
Validation phase is also known as optimistic concurrency control technique. In
the validation based protocol, the transaction is executed in the following three
phases:

Read phase: In this phase, the transaction T is read and executed. It is used to
read the value of various data items and stores them in temporary local
variables. It can perform all the write operations on temporary variables without
an update to the actual database.
Validation phase: In this phase, the temporary variable value will be validated
against the actual data to see if it violates the serializability.
Write phase: If the validation of the transaction is validated, then the temporary
results are written to the database or system otherwise the transaction is rolled
back.
Here each phase has the following different timestamps:
Start(Ti): It contains the time when Ti started its execution.
Validation (Ti): It contains the time when Ti finishes its read phase and starts
its validation phase.

You might also like