0% found this document useful (0 votes)
44 views103 pages

DBMS (4CS4-05) - Solution-Model Guess Paper

The document is a model guess paper solution for a Database Management System course, outlining key concepts, definitions, and applications related to DBMS. It includes short answer questions on topics such as the role of a DBA, data models, advantages of DBMS over file systems, and the structure of DBMS. Additionally, it covers the differences between logical and physical data independence, and provides insights into ER diagrams and their components.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views103 pages

DBMS (4CS4-05) - Solution-Model Guess Paper

The document is a model guess paper solution for a Database Management System course, outlining key concepts, definitions, and applications related to DBMS. It includes short answer questions on topics such as the role of a DBA, data models, advantages of DBMS over file systems, and the structure of DBMS. Additionally, it covers the differences between logical and physical data independence, and provides insights into ER diagrams and their components.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 103

ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY

MODEL GUESS PAPER SOLUTION


(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

UNIT-01

Part: A (Unit-01) [Short Answer Type, 2-3 Marks Each]

Q. 1 Define Database Management System?

Ans: Database is a collection of related data and data is a collection of facts and figures that can be processed to
produce information.

Mostly data represents recordable facts. Data aids in producing information, which is based on facts. For example,
if we have data about marks obtained by all students, we can then conclude about toppers and average marks.

A database management system stores data in such a way that it becomes easier to retrieve, manipulate, and
produce information.

Q. 2 Who is DBA? What is the role of DBA in DBMS?


Ans: Database administrators (DBAs) use specialized software to store and organize data. The role may include
capacity planning, installation, configuration, database design, migration, performance monitoring, security,
troubleshooting, as well as backup and data recovery

Q. 3 What is Data Model? List the types of Data Model.


Ans: Data models define how the logical structure of a database is modeled. Data Models are fundamental entities
to introduce abstraction in a DBMS. Data models define how data is connected to each other and how they are
processed and stored inside the system.

The very first data model could be flat data-models, where all the data used are to be kept in the same plane.
Earlier data models were not so scientific, hence they were prone to introduce lots of duplication and update
anomalies.

It shows the relationship between data. A Model is basically a conceptualization between attributes and entities.
There were basically three main data models in DBMS that were Network, hierarchical, and relational.

Q. 4 What are the Applications of DBMS list any five only?

Ans: Application and Uses of Database Management System (DBMS): Due the evolution of Database
management system, companies are getting more from their work because they can keep records of everything.
Also it makes them faster to search information and records about any people or product that makes them more
effective in work. So here we are sharing some of the applications and uses of database management system
(DBMS).
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Application and Uses of Database Management System (DBMS)

Railway Reservation System

Database is required to keep record of ticket booking, train’s departure and arrival status. Also if trains get late
then people get to know it through database update.

Library Management System

There are thousands of books in the library so it is very difficult to keep record of all the books in a copy or
register. So DBMS used to maintain all the information relate to book issue dates, name of the book, author and
availability of the book.

Banking

We make thousands of transactions through banks daily and we can do this without going to the bank. So how
banking has become so easy that by sitting at home we can send or get money through banks. That is all possible
just because of DBMS that manages all the bank transactions.

Universities and colleges

Examinations are done online today and universities and colleges maintain all these records through DBMS.
Student’s registrations details, results, courses and grades all the information are stored in database.

Credit card transactions

For purchase of credit cards and all the other transactions are made possible only by DBMS. A credit card holder
knows the importance of their information that all are secured through DBMS.

Q. 5 What are the disadvantage of File System list any four?


Ans: Data Redundancy: ...
 Data Inconsistency: ...
 Difficulty in Accessing Data: ...

 Limited Data Sharing: ...


 Integrity Problems: ...
 Atomicity Problems: ...
 Concurrent Access Anomalies: ...
 Security Problems:

Q. 6 State the different levels in DBMS Architecture?


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Ans: Physical Level. This is the lowest level in the three level architecture. It is also known as the internal level.

 Conceptual Level. The conceptual level is at a higher level than the physical level. ...
 External Level. This is the highest level in the three level architecture and closest to the user.

Q. 7 Why Roll number or serial no. of a student is taken as Primary key in a table?
Ans: Roll number is a unique number by which we can uniquely identified a student from a list of student
containing huge data of student. So we can make roll number as a Primary key and use this key for
identified the full information of that particular student.

Q. 8 What is storage manager?


Ans: The raw data are stored on the disk using the file system, which is usually provided by a conventional
operating system. The storage manager translates the various DML statements into low-level file-system
commands. Thus, the storage manager is responsible for storing, retrieving, and updating data in the database.

Q. 9 What are Attributes?


Ans: In general, an attribute is a characteristic. In a database management system (DBMS), an attribute refers
to a database component, such as a table. It also may refer to a database field. Attributes describe the instances in
the row of a database.

Q. 10 Write the symbols which are used in E-R Diagram.


Ans:
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Part: B (Unit-01) [Subjective, 8-10 Marks Each]


Q. 1. Explain the advantages of DBMS over File management system.

Ans: Advantages of DBMS over File system –

 Data redundancy and inconsistency – Redundancy is the concept of repetition of data i.e. each data may
have more than a single copy. The file system cannot control redundancy of data as each user defines and
maintains the needed files for a specific application to run. There may be a possibility that two users are
maintaining same files data for different applications. Hence changes made by one user does not reflect in
files used by second users, which leads to inconsistency of data. Whereas DBMS controls redundancy by
maintaining a single repository of data that is defined once and is accessed by many users. As there is no or
less redundancy, data remains consistent.
 Data sharing – File system does not allow sharing of data or sharing is too complex. Whereas in DBMS,
data can be shared easily due to centralized system.
 Data concurrency – Concurrent access to data means more than one user is accessing the same data at the
same time. Anomalies occur when changes made by one user gets lost because of changes made by other
user. File system does not provide any procedure to stop anomalies. Whereas DBMS provides a locking
system to stop anomalies to occur.
 Data searching – For every search operation performed on file system, a different application program has
to be written. While DBMS provides inbuilt searching operations. User only have to write a small query to
retrieve data from database.
 Data integrity – There may be cases when some constraints need to be applied on the data before inserting
it in database. The file system does not provide any procedure to check these constraints automatically.
Whereas DBMS maintains data integrity by enforcing user defined constraints on data by itself.

Q. 2. What is the difference between logical and physical data independence.


Ans:

PHYSICAL DATA INDEPENDENCE:

 physical storage structure or devices can be changed without affecting conceptual schema
 Modification are performed to improve performance
 It is not difficult because, we have to only replace the data from one device to another device. No need to
change the data only change the location of data
 It provide independence and immunity to conceptual and external schema

LOGICAL DATA INDEPENDENCE:


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

 Conceptual schema can be changed without affecting external schema


 We change/modify conceptual schema when structure of database is altered
 It is very difficult because, we have to see that the relationship must not changing, data is not getting lost
and some other factors
 It only provide immunity to external schema and application program

Q. 3. Draw the diagram of system structure of DBMS. Write down main function of each component.
Ans: Structure of DBMS:
 DBMS (Database Management System) acts as an interface between the user and the database. The user
requests the DBMS to perform various operations such as insert, delete, update and retrieval on the
database.
 The components of DBMS perform these requested operations on the database and provide necessary data
to the users.

 The various components of DBMS are described below:

Components of a DBMS

The components of DBMS can be divided into two parts:

Function and Services of DBMS


1. DDL Compiler:
o Data Description Language compiler processes schema definitions specified in the DDL.

o It includes metadata information such as the name of the files, data items, storage details of each
file, mapping information and constraints etc.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

2. DML Compiler and Query optimizer:


o The DML commands such as insert, update, delete, retrieve from the application program are sent
to the DML compiler for compilation into object code for database access.
o The object code is then optimized in the best way to execute a query by the query optimizer and
then send to the data manager.
3. Data Manager:
o The Data Manager is the central software component of the DBMS also knows as Database Control
System.
o The Main Functions Of Data Manager Are:

1. Convert operations in user's Queries coming from the application programs or combination
of DML Compiler and Query optimizer which is known as Query Processor from user's
logical view to physical file system.
2. Controls DBMS information access that is stored on disk.
3. It also controls handling buffers in main memory.
4. It also enforces constraints to maintain consistency and integrity of the data.
5. It also synchronizes the simultaneous operations performed by the concurrent users.
6. It also controls the backup and recovery operations.
4. Data Dictionary:
o Data Dictionary, which stores metadata about the database, in particular the schema of the database.

o names of the tables, names of attributes of each table, length of attributes, and number of rows in
each table.
o Detailed information on physical database design such as storage structure, access paths, files and
record sizes.
o Usage statistics such as frequency of query and transactions.

o Data dictionary is used to actually control the data integrity, database operation and accuracy. It
may be used as a important part of the DBMS
5. Data Files:
o Which store the database itself.

6. Compiled DML:
o The DML complier converts the high level Queries into low level file access commands known as
compiled DML.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

7. End Users:
o The second class of users then is end user, who interacts with system from online workstation or
terminals.
o Use the interface provided as an integral part of the database system software.

1. User can request, in form of query, to access database either directly by using particular language,
such as SQL, or by using some pre-developed application interface.
2. Such request are sent to query evaluation engine via DML pre-compiler and DML compiler

3. The query evaluation engine accepts the query and analyses it.

4. It finds the suitable way to execute the compiled SQL statements of the query.

5. Finally, the compiled SQL statements are executed to perform the specified operation

6. Query Processor Units:

Interprets DDL statements into a set of tables containing metadata.


Translates DML statements into low level instructions that the query evaluation engine understands.
Converts DML statements embedded in an application program into procedure calls int he host
language.
Executes low level instructions generated by DML compiler.

a. DDL Interpreter
b. DML Compiler
c. Embedded DML Pre-compiler
d. Query Evolution Engine
2. Storage Manager Units

Checks the authority of users to access data.

Checks for the satisfaction of the integrity constraints.

Preserves atomicity and controls concurrency.

Manages allocation of splace on disk.

Fetches data from disk storage to memory for being used.


a. Authorization Manager
b. Integrity Manager
c. Transaction Manager
d. File manager
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

e. Buffer Manager

 Functions of DBMS:

o DBMS free the programmers from the need to worry about the organization and location of
the data i.e. it shields the users from complex hardware level details.
o DBMS can organize process and present data elements from the database. This capability
enables decision makers to search and query database contents in order to extract answers
that are not available in regular Reports.
o Programming is speeded up because programmer can concentrate on logic of the
application.
o It includes special user friendly query languages which are easy to understand by non
programming users of the system.
 The service provided by the DBMS includes :-

o Authorization services like log on to the DBMS start the database stop the Database etc.
o Transaction supports like Recovery, Rollback etc,
o Import and Export of Data.
o Maintaining data dictionary
o User's Monitoring

Q. 4. What is ER-diagram? Generate a ER Diagram for bank enterprise.


Ans: Entity-Relationship Model

Entity-Relationship (ER) Model is based on the notion of real-world entities and relationships among them. While
formulating real-world scenario into the database model, the ER Model creates entity set, relationship set, general
attributes and constraints.

ER Model is best used for the conceptual design of a database.

ER Model is based on −

 Entities and their attributes.


 Relationships among entities.

These concepts are explained below.


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

 Entity − An entity in an ER Model is a real-world entity having properties called attributes. Every
attribute is defined by its set of values called domain. For example, in a school database, a student is
considered as an entity. Student has various attributes like name, age, class, etc.
 Relationship − The logical association among entities is called relationship. Relationships are mapped
with entities in various ways. Mapping cardinalities define the number of association between two entities.

Mapping cardinalities −

o one to one
o one to many

o many to one

o many to many
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Q. 5. Write short notes on.


1. Aggregation

Ans: Aggregation –An ER diagram is not capable of representing relationship between an entity and a
relationship which may be required in some scenarios. In those cases, a relationship with its corresponding entities
is aggregated into a higher level entity. For Example, Employee working for a project may require some
machinery. So, REQUIRE relationship is needed between relationship WORKS_FOR and entity MACHINERY.
Using aggregation, WORKS_FOR relationship with its entities EMPLOYEE and PROJECT is aggregated into
single entity and relationship REQUIRES is created between aggregated entity and MACHINERY.

2. Attribute

Ans: An attribute is a part of the dbms. It is property of an entity. Every Entity(relation) has attributes. For eg: If I
am creating a database of students with their details. So I ll first create a table with name “Student”. This table is
our entity(relation). Now this entity shall have attributes like “student_name”,”student_id”,”roll_no” which will
form the columns of the table. All written in ““shall be the attributes for the table “student”
3. Weak Entity
Ans: An entity set that does not have a primary key is referred to as a weak entity set.
The existence of a weak entity set depends on the existence of a strong entity set; it must relate to the
strong set via a on-to-many relationship set.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

A distriminator of a weak entity set is the set of attributes that distinguishes among all the entities of a
weak entity set.
The primary key of a weak entity set is formed by the primary key of the strong entity set on which the
weak entity set is existence depend, plus the weak entity set’s discriminator.

4. Binary and Ternary Relationship


Ans: The binary relation is used when two entities have relation directly with each other, here directly is mean a
key on child relation should refer to a value which is available on parent table identity/unique key. something like
this.

The Ternary, when three or (n) relations have relationship between themselves, and providing all relationship
between them makes the database complex, so here the relationships will turned into a relation which has one-to-
many/one to-one with base relations.
Example: consider an event in OS, an event would associate with application which registered the event, the
device which caused the event, and the component (textbox, button, window,) which triggered the event.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Q. 6. Define key. Explain the distinctions among term primary key, candidate key and super key with
example.

Ans: Keys are very important part of Relational database model. They are used to establish and identify
relationships between tables and also to uniquely identify any record or row of data inside a table.

A Key can be a single attribute or a group of attributes, where the combination may act as a key.

Super Key

Super Key is defined as a set of attributes within a table that can uniquely identify each record within a table.
Super Key is a superset of Candidate key.

In the table defined above super key would include student_id, (student_id, name), phone etc.

Confused? The first one is pretty simple as student_id is unique for every row of data, hence it can be used to
identity each row uniquely.

Next comes, (student_id, name), now name of two students can be same, but their student_id can't be same hence
this combination can also be a key.

Similarly, phone number for every student will be unique, hence again, phone can also be a key.

So they all are super keys.

Candidate Key

Candidate keys are defined as the minimal set of fields which can uniquely identify each record in a table. It is an
attribute or a set of attributes that can act as a Primary Key for a table to uniquely identify each record in that table.
There can be more than one candidate key.

In our example, student_id and phone both are candidate keys for table Student.

 A candiate key can never be NULL or empty. And its value should be unique.
 There can be more than one candidate keys for a table.
 A candidate key can be a combination of more than one columns(attributes).

Primary Key

Primary key is a candidate key that is most appropriate to become the main key for any table. It is a key that can
uniquely identify each record in a table.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

For the table Student we can make the student_id column as the primary key.

Composite Key

Key that consists of two or more attributes that uniquely identify any record in a table is called Composite key.
But the attributes which together form the Composite key are not a key independentely or individually.

In the above picture we have a Score table which stores the marks scored by a student in a particular subject.

In this table student_id and subject_id together will form the primary key, hence it is a composite key.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Part: C (Unit-01) [Long Answer Type, 15 Marks Each]

Q. 1 Why we need DBMS over file system. List the difference between file system and DBMS also states the
advantage and disadvantage of DBMS in details.

Ans: File Management System, better known as File System is the most ancient and still the most popular way to
keep your data files organised on your drives.

On the other hand, when it comes to security and appropriate management of data based on constraints and other
stuff that we are going to talk about, the first choice of many experts, is Database Management System (DBMS).

So what are they? What are the parameters to decide the best one for your need? Let’s come to these aspects now.

File Systems is the traditional way to keep your data organised in a way which is easy for physical access, whether
it’s on your shelf or on the drives.

Earlier people used to keep records and maintain data in registers and any alteration/retrieval to this data was
difficult. When computers came, same agenda was followed for storing the data on drives.

File System actually stores data in the form of isolated files which have their own set of property table and
physical location on the drive and user manually goes to these locations to access the files.

It is an easy way to store data in general files like images, text, videos, audios etc., but security is less because only
options available to these files are the options given by the operating system such as locks, hidden files and
sharing. These files are hard to maintain when it comes to frequent changes to these files.

Data redundancy is more and can’t be controlled easily. Data integration is hard to achieve and also data
consistency is not met.

Database Management System, abbreviated as DBMS, is an effective way to store the data when constraints are
high and data maintenance and security are the primary concern of the user.

DBMS stores data in the form of interrelated tables and files. These are generally consist of database management
system providers that are used to store and manipulate databases, hardware where the data is physically stored and
an user friendly software developed to met specific purpose in certain situations, using which user can easily
access database without worrying about the underlying schema of the database.

Database Management System is great way to manage data as, the data redundancy is minimized due to
interrelation of data entities and also provide a procedure for data integration due to centralisation of data in the
database. Security of data is also maximized using password protection, encryption/decryption, granting
authorized access and others.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

File System vs DBMS – Difference between File System and DBMS

File Management System Database Management System

File System is a general, easy-to-use system to


Database management system is used when
store general files which require less security
security constraints are high.
and constraints.

Data Redundancy is more in file management Data Redundancy is less in database


system. management system.

Data Inconsistency is less in database


Data Inconsistency is more in file system.
management system.

Centralisation is hard to get when it comes to Centralisation is achieved in Database


File Management System. Management System.

In Database Management System, user is


User locates the physical address of the files to
unaware of physical address where data is
access data in File Management System.
stored.

Security is high in Database Management


Security is low in File Management System.
System.

Database Management System stores structured


File Management System stores unstructured
data which have well defined constraints and
data as isolated data files/entities.
interrelation

Q. 2 Explain DBMS Architecture in detail with different levels and schema.

Ans: The design of a DBMS depends on its architecture. It can be centralized or decentralized or hierarchical. The
architecture of a DBMS can be seen as either single tier or multi-tier. An n-tier architecture divides the whole
system into related but independent n modules, which can be independently modified, altered, changed, or
replaced.

In 1-tier architecture, the DBMS is the only entity where the user directly sits on the DBMS and uses it. Any
changes done here will directly be done on the DBMS itself. It does not provide handy tools for end-users.
Database designers and programmers normally prefer to use single-tier architecture.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

If the architecture of DBMS is 2-tier, then it must have an application through which the DBMS can be accessed.
Programmers use 2-tier architecture where they access the DBMS by means of an application. Here the application
tier is entirely independent of the database in terms of operation, design, and programming.

3-tier Architecture

A 3-tier architecture separates its tiers from each other based on the complexity of the users and how they use the
data present in the database. It is the most widely used architecture to design a DBMS.

 Database (Data) Tier − At this tier, the database resides along with its query processing languages. We
also have the relations that define the data and their constraints at this level.
 Application (Middle) Tier − At this tier reside the application server and the programs that access the
database. For a user, this application tier presents an abstracted view of the database. End-users are
unaware of any existence of the database beyond the application. At the other end, the database tier is not
aware of any other user beyond the application tier. Hence, the application layer sits in the middle and acts
as a mediator between the end-user and the database.

 User (Presentation) Tier − End-users operate on this tier and they know nothing about any existence of
the database beyond this layer. At this layer, multiple views of the database can be provided by the
application. All views are generated by applications that reside in the application tier.

Multiple-tier database architecture is highly modifiable, as almost all its components are independent and can be
changed independently.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Database Schema

A database schema is the skeleton structure that represents the logical view of the entire database. It defines how
the data is organized and how the relations among them are associated. It formulates all the constraints that are to
be applied on the data.

A database schema defines its entities and the relationship among them. It contains a descriptive detail of the
database, which can be depicted by means of schema diagrams. It’s the database designers who design the schema
to help programmers understand the database and make it useful.

A database schema can be divided broadly into two categories −

 Physical Database Schema − This schema pertains to the actual storage of data and its form of storage
like files, indices, etc. It defines how the data will be stored in a secondary storage.
 Logical Database Schema − This schema defines all the logical constraints that need to be applied on the
data stored. It defines tables, views, and integrity constraints.

Q. 3 What are Attributes, Derived Attributes and Meta Data in DBMS?

Ans: Attributes:-Generally attribute constitutes a character and explains the characteristics of an entity. In
database management system (DBMS) it assigns a database component or database field. Attribute stores or saves
only a piece of data. For example, in an invoice the attribute may be the price or date. In this article, we will
discuss the various types of attributes with examples.

Types of Attributes with Examples

The different types of attributes are as follows

 Single valued attributes


 Multi valued attributes

 Compound /Composite attributes

 Simple / Atomic attributes

 Stored attributes

 Derived attributes

 Complex attributes
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

 Key attributes

 Non key attributes

 Required attributes

Drived Atteributes

If an attribute's value can be determined from the values of other attributes, then the attribute is derivable, and is
said to be a derived attribute.

If an attribute's value can be derived from other attributes, you should consider dropping the attribute from the
model. Perhaps you would keep it, if keeping it helped understandability (you can still decide to drop the attribute
from the physical model). Derived attributes are shown with a dotted lined oval, see the figure below.

Sometimes an attribute of one entity is derived from attributes in other entities. Consider the attribute for the total
of an Invoice, InvTotal. A value of InvTotal is derivable; it can be computed by knowing the value of
InvLineAmount from each related invoice line. Keeping an attribute such as InvTotal in the model can easily
promote communication with other interested parties (other business users). This example also indicates a situation
where deriving a value (on-the-fly) could be an expensive operation to perform (to determine the value of an
invoice would mean accessing all relevant invoice line data in the database). Such an attribute may find its way
into the eventual physical model for that reason.

Meta Data

Metadata is data about data. In other words, it's information that's used to describe the data that's contained in
something like a web page, document, or file. Another way to think of metadata is as a short explanation or
summary of what the data is.

A simple example of metadata for a document might include a collection of information like the author, file size,
date the document was created, and keywords to describe the document. Metadata for a music file might include
the artist's name, the album, and the year it was released.

Metadata represents behind-the-scenes information that's used everywhere, by every industry, in multiple ways.
It's ubiquitous in information systems, social media, websites, software, music services, and online retailing.
Metadata can be created manually to pick and choose what's included, but it can also be generated automatically
based on the data.

Q. 4 Explain the various keys in DBMS and also create a table and justify the keys by the particular table
with a reason.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Ans: Keys are very important part of Relational database model. They are used to establish and identify
relationships between tables and also to uniquely identify any record or row of data inside a table.

A Key can be a single attribute or a group of attributes, where the combination may act as a key.

Super Key

Super Key is defined as a set of attributes within a table that can uniquely identify each record within a table.
Super Key is a superset of Candidate key.

In the table defined above super key would include student_id, (student_id, name), phone etc.

Confused? The first one is pretty simple as student_id is unique for every row of data, hence it can be used to
identity each row uniquely.

Next comes, (student_id, name), now name of two students can be same, but their student_id can't be same hence
this combination can also be a key. Similarly, phone number for every student will be unique, hence again, phone
can also be a key. So they all are super keys.

Candidate Key

Candidate keys are defined as the minimal set of fields which can uniquely identify each record in a table. It is an
attribute or a set of attributes that can act as a Primary Key for a table to uniquely identify each record in that table.
There can be more than one candidate key.

In our example, student_id and phone both are candidate keys for table Student.

 A candiate key can never be NULL or empty. And its value should be unique.
 There can be more than one candidate keys for a table.

 A candidate key can be a combination of more than one columns(attributes).

Primary Key

Primary key is a candidate key that is most appropriate to become the main key for any table. It is a key that can
uniquely identify each record in a table.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

For the table Student we can make the student_id column as the primary key.

Composite Key

Key that consists of two or more attributes that uniquely identify any record in a table is called Composite key.
But the attributes which together form the Composite key are not a key independentely or individually.

In the above picture we have a Score table which stores the marks scored by a student in a particular subject.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

In this table student_id and subject_id together will form the primary key, hence it is a composite key.

Q. 5 What is a Domain in an Attribute explain with an example

Ans: Domain A domain is defined as the set of all unique values permitted for an attribute. For example, a domain
of date is the set of all possible valid dates, a domain of integer is all possible whole numbers, a domain of day-of-
week is Monday, Tuesday ... Sunday.

This in effect is defining rules for a particular attribute. If it is determined that an attribute is a date then it should
be implemented in the database to prevent invalid dates being entered. Each domain contains one or more entities.
An entity is a set of related attributes, and an attribute is basically a field value. For a description of all entities and
attributes, see Entities and Attributes.

Attribute In general, an attribute is a characteristic. In a database management system (DBMS), an attribute


refers to a database component, such as a table. It also may refer to a database field. Attributes describe the
instances in the row of a database.

Q. 6 What do you mean by Entity and Entity Set in DBMS with an example.

Ans: Entities and Entity Sets

 An entity is an object that exists and is distinguishable from other objects. For instance, John Harris with
S.I.N. 890-12-3456 is an entity, as he can be uniquely identified as one particular person in the universe.
 An entity may be concrete (a person or a book, for example) or abstract (like a holiday or a concept).

 An entity set is a set of entities of the same type (e.g., all persons having an account at a bank).

 Entity sets need not be disjoint. For example, the entity set employee (all employees of a bank) and the
entity set customer (all customers of the bank) may have members in common.

 An entity is represented by a set of attributes.

o E.g. name, S.I.N., street, city for ``customer'' entity.

o The domain of the attribute is the set of permitted values (e.g. the telephone number must be seven
positive integers).
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

 Formally, an attribute is a function which maps an entity set into a domain.

o Every entity is described by a set of (attribute, data value) pairs.

o There is one pair for each attribute of the entity set.

o E.g. a particular customer entity is described by the set {(name, Harris), (S.I.N., 890-123-456),
(street, North), (city, Georgetown)}.

An analogy can be made with the programming language notion of type definition.

 The concept of an entity set corresponds to the programming language type definition.
 A variable of a given type has a particular value at a point in time.

 Thus, a programming language variable corresponds to an entity in the E-R model.

We will be dealing with five entity sets in this section:

 branch, the set of all branches of a particular bank. Each branch is described by the attributes branch-
name, branch-city and assets.
 customer, the set of all people having an account at the bank. Attributes are customer-name, S.I.N., street
and customer-city.

 employee, with attributes employee-name and phone-number.

 account, the set of all accounts created and maintained in the bank. Attributes are account-number and
balance.

 transaction, the set of all account transactions executed in the bank. Attributes are transaction-number,
date and amount.

Example :

Suppose we consider a school database to explain entity and entity set. So let’s gets started.

In school database student , teacher, class and course can be treated as entities because all these entities has to have
some attributes that given their identity. In school database student set can be treated as entity set because it
contains all the student entity of the school.

UNIT-02

Part: A (Unit-02) [Short Answer Type, 2-3 Marks Each]


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Q. 1 What is the main difference between Selection and Projection?

Ans: Select Operation : This operation is used to select rows from a table (relation) that specifies a given logic,
which is called as a predicate. The predicate is a user defined condition to select rows of user's choice.

Project Operation : If the user is interested in selecting the values of a few attributes, rather than selection all
attributes of the Table (Relation), then one should go for PROJECT Operation.

Q. 2 What do you understand by the term Renaming in Relation Algebra?

Ans: Rename Operation (ρ):- The results of relational algebra are also relations but without any name. The
rename operation allows us to rename the output relation. 'rename' operation is denoted with small Greek letter
rho ρ.

Notation − ρ x (E)

Where the result of expression E is saved with name of x.

Additional operations are −

 Set intersection
 Assignment

 Natural join

Q. 3 Define Relation Calculus.

Ans: Relational calculus is a query language which is non-procedural, and instead of algebra, it uses
mathematical predicate calculus. The relational calculus is not the same as that of differential and integral
calculus in mathematics but takes its name from a branch of symbolic logic termed as predicate calculus.

Q. 4 What is the major difference between inner and outer joins.

Ans: Both inner and outer joins are used to combine rows from two or more tables into a single result. This is
done using a join condition. The join condition specifies how columns from each table are matched to one
another. In most cases the aim is to find equal values between tables, and include those matches. The most
common case for this is when you’re matching the foreign key of one table to the primary key of another, such as
when using and ID to lookup a value. Though both inner and outer joins include rows from both tables when the
match condition is successful, they differ in how they handle a false match condition. Inner joins don’t include
non-matching rows; whereas, outer joins do include them.

Q. 5 Why Joins are used in the Relation tables?


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Ans: Using Joins. The SQL Joins clause is used to combine records from two or more tables in a database. A
JOIN is a means for combining fields from two tables by using values common to each. ... INNER JOIN −
returns rows when there is a match in both tables.

Q. 6 What is SQL queries in dbms?

Ans: A query is a request for data or information from a database table or combination of tables. This data may be
generated as results returned by Structured Query Language (SQL) or as pictorials, graphs or complex results,
e.g., trend analyses from data-mining tools.

Q. 7 Define JDBC & ODBC?

Ans: ODBC is for Microsoft and JDBC is for java applications.ODBC is used to provide connection between
front-end application(other than java) and back-end (database like ms-access) and JDBC is used to provide
connection between JAVA and database(oracle,sybase,DB2,ms-access).

Q. 8 What do you mean by Embedded SQL?

Ans: Embedded SQL is a method of combining the computing power of a programming language and the
database manipulation capabilities of SQL. Embedded SQL statements are SQL statements written inline with
the program source code , of the host language.

Q. 9 What are Triggers.

Ans: A database trigger is special stored procedure that is run when specific actions occur within a database. Most
triggers are defined to run when changes are made to a table’s data. Triggers can be defined to run instead of or
after DML (Data Manipulation Language) actions such as INSERT, UPDATE, and DELETE.Triggers help the
database designer ensure certain actions, such as maintaining an audit file, are completed regardless of which
program or user makes changes to the data.

Q. 10 What is DDL, DML & DCL in SQL?

Ans: DDL(Data Definition Language) : DDL or Data Definition Language actually consists of the SQL
commands that can be used to define the database schema. It simply deals with descriptions of the database
schema and is used to create and modify the structure of database objects in database.

DML(Data Manipulation Language) : The SQL commands that deals with the manipulation of data present in
database belong to DML or Data Manipulation Language and this includes most of the SQL statements.

DCL(Data Control Language) : DCL includes commands such as GRANT and REVOKE which mainly deals
with the rights, permissions and other controls of the database system.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Part: B (Unit-02) [Subjective Type, 8-10 Marks Each]


Q. 1. What is the difference between relation algebra and relation calculus.
Ans: Definition of Relational Algebra

Relational algebra presents the basic set of operations for relational model. It is a procedural language, which
describes the procedure to obtain the result. Relational algebra is prescriptive because it describes the order of
operations in the query that specifies how to retrieve the result of a query.

The sequence of operations in a relation algebra is called relational algebra expression. The Relational Algebra
Expression either takes one relation or two relations as an input to the expression and produces a new relation as a
result. The resultant relation obtained from the relational algebra expressions can be further composed to the other
relational algebra expression whose result will again be a new relation.

The Relation Algebra forms the framework for implementing and optimizing queries while query processing.
Relational algebra is an integral part of relational DBMS. The fundamental operation included in relational
algebra are { Select (σ), Project (π), Union (∪ ), Set Difference (-), Cartesian product (×) and Rename (ρ)}.

Definition of Relational Calculus

Unlike Relational Algebra, Relational Calculus is a higher level Declarative language. In converse to the
relational algebra, relational calculus defines what result is to be obtained. Like Relational Algebra, Relational
Calculus does not specify the sequence of operations in which query will be evaluated.

The sequence of relational calculus operations is called relational calculus expression that also produces a new
relation as a result. The Relational Calculus has two variations namely Tuple Relational Calculus and Domain
Relational Calculus.

Content: Relational Algebra Vs Relational Calculus

Comparison Chart
Basis for
Relational Algebra Relational Calculus
Comparison

Relational Claculus is Declarative


Basic Relational Algebra is a Procedural language.
language.

Relational Calculus states what result we


States Relational Algebra states how to obtain the result.
have to obtain.

Relational Algebra describes the order in which Relational Calculus does not specify the
Order
operations have to be performed. order of operations.

Relation Claculus can be domain


Domain Relational Algebra is not domain dependent.
dependent.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Basis for
Relational Algebra Relational Calculus
Comparison

Related It is close to a programming language. It is close to the natural language.

Q. 2. Explain expressive power of algebra and calculus.


Ans: For a calculus formula Q to be considered safe, at a minimum we want to ensure that for any given I, the set
of answers for Q contains only values that are in Dom(Q, I). While this restriction is obviously required, it is not
enough. Not only do we want the set of answers to be composed of constants in Dom(Q, I), we wish to compute

leads to a subtle point associated with the use of quantifiers ∀ and ∃: Given a TRC formula of the form ∃R(p(R)),
the set of answers by only examining tuples that contain constants in Dom(Q, I)! This wish

we want to find all values for variable R that make this formula true by checking only tuples that contain constants
in Dom(Q, I). Similarly,

given a TRC formula of the form ∀R(p(R)), we want to find any values for variable R that make this formula false
by checking only tuples that contain constants in Dom(Q, I).
We therefore define a safe TRC formula Q to be a formula such that:

2. For each subexpression of the form ∃R(p(R)) in Q, if a tuple r (assigned to variable R) makes the formula true,
1. For any given I, the set of answers for Q contains only values that are in Dom(Q, I).

3. For each subexpression of the form ∀R(p(R)) in Q, if a tuple r (assigned to variableR) contains a constant that is
then r contains only constants in Dom(Q, I).

not in Dom(Q, I), then r must make the formula


true.

The query Q = {S | ¬(S ∈ Sailors)} is unsafe by this definition. Dom(Q,I) is the set of all values that appear in (an
Note that this definition is not constructive, that is, it does not tell us how to chek if a query is safe.

instance I of) Sailors. Consider the instance S1 shown in Figure 4.1. The answer to this query obviously includes
values that do not appear in Dom(Q, S1).
Returning to the question of expressiveness, we can show that every query that can be expressed using a safe
relational calculus query can also be expressed as a relational algebra query. The expressive power of relational
algebra is often used as a metric of how powerful a relational database query language is. If a query language can
express all the queries that we can express in relational algebra, it is said to be relationally complete. A practical
query language is expected to be relationally complete; in addition, commercial query languages typically support
features that allow us to express some queries that cannot be expressed in relational algebra.

Q. 3. Discuss the various types of keys used in Relational model.

Ans: Candidate Key: The minimal set of attribute which can uniquely identify a tuple is known as candidate key.
For Example, STUD_NO in STUDENT relation.

 The value of Candidate Key is unique and non-null for every tuple.
 There can be more than one candidate key in a relation. For Example, STUD_NO as well as
STUD_PHONE both are candidate keys for relation STUDENT.
 The candidate key can be simple (having only one attribute) or composite as well. For Example,
{STUD_NO, COURSE_NO} is a composite candidate key for relation STUDENT_COURSE.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Note – In Sql Server a unique constraint that has a nullable column, allows the value ‘null‘ in that column only
once. That’s why STUD_PHONE attribute as candidate here, but cannot be ‘null’ values in primary key attribute.

Super Key: The set of attributes which can uniquely identify a tuple is known as Super Key. For Example,
STUD_NO, (STUD_NO, STUD_NAME) etc.

 Adding zero or more attributes to candidate key generates super key.


 A candidate key is a super key but vice versa is not true.

Primary Key: There can be more than one candidate key in a relation out of which one can be chosen as primary
key. For Example, STUD_NO as well as STUD_PHONE both are candidate keys for relation STUDENT but
STUD_NO can be chosen as primary key (only one out of many candidate keys).

Alternate Key: The candidate key other than primary key is called as alternate key. For Example, STUD_NO as
well as STUD_PHONE both are candidate keys for relation STUDENT but STUD_PHONE will be alternate key
(only one out of many candidate keys).

Foreign Key: If an attribute can only take the values which are present as values of some other attribute, it will be
foreign key to the attribute to which it refers. The relation which is being referenced is called referenced relation
and corresponding attribute is called referenced attribute and the relation which refers to referenced relation is
called referencing relation and corresponding attribute is called referencing attribute. Referenced attribute of
referencing attribute should be primary key. For Example, STUD_NO in STUDENT_COURSE is a foreign key to
STUD_NO in STUDENT relation.

Q. 4. Consider following database


Bank Database Schema:
account(account_number, branch_name, balance)
branch (branch_name, branch_city, assets)
customer (customer_name customer_street, customer_city)
loan (loan_number, branch_name, amount)
depositor((customer_name, account_number)
borrower(customer_name, loan_number)

Retrieving records from a table:

1. List all branch names and their assests


2. List all accounts of Brooklyn branch
3. List all loans with amount > 1000.
4. List all accounts of Perryridge branch with balance < 1000.
5. List Numbers of accounts with balances between 700 and 900

Ans:
1. Select branch_name,assests from branch
2. Select account from account where branch-name =’ Brooklyn’
3. Select * from loan where amount >1000
4. Select * from account where branch_name=’ Perryridge’ and balance <1000
5. Select count(*) from accounts where balance between 700 and 900
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Q. 5. What are triggers? Explain how it works in DBMS.


Ans: A database trigger is special stored procedure that is run when specific actions occur within a database. Most
triggers are defined to run when changes are made to a table’s data. Triggers can be defined to run instead of or
after DML (Data Manipulation Language) actions such as INSERT, UPDATE, and DELETE.

Triggers help the database designer ensure certain actions, such as maintaining an audit file, are completed
regardless of which program or user makes changes to the data.

The programs are called triggers since an event, such as adding a record to a table, fires their execution.

How Triggers Are Used


In many cases, triggers supplement the standard capabilities of Oracle to provide a highly customized database
management system. For example, a trigger can permit DML operations against a table only if they are issued
during regular business hours. The standard security features of Oracle, roles and privileges, govern which users
can submit DML statements against the table. In addition, the trigger further restricts DML operations to occur
only at certain times during weekdays. This is just one way that you can use triggers to customize information
management in an Oracle database.

In addition, triggers are commonly used to

 automatically generate derived column values

 prevent invalid transactions

 enforce complex security authorizations

 enforce referential integrity across nodes in a distributed database

 enforce complex business rules

 provide transparent event logging

 provide sophisticated auditing

 maintain synchronous table replicates

 gather statistics on table access

Q. 6. Explain following operations in relational algebra with suitable examples:

1.Rename
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Ans: The results of relational algebra are also relations but without any name. The rename operation provides
database designers to rename the output relation. The rename-operation is denoted using small Greek letter rho (ρ).

It is written as:

ρ x (E)

2.Natural Join
Ans: The natural join operation: - it is a binary operation and a combination of certain selections and a
Cartesian product into one operation.

 It is denoted as |X| .
 It is associative.

It forms a Cartesian product of its two arguments.


Then performs a selection forcing equality on those attributes those appear in both the relations.
And finally removes duplicates attributes.

r(R): r is a relation with attributes R.


s(S): s is a relation with attributes S.

If R ∩ S = Ф i.e. they have no attributes in common then r |X| s = r X s

3.Division
Ans: The division / quotient operation: -

 It is denoted as ÷.
Letr(R) and s(S) be relations

r ÷ s: - the result consists of the restrictions of tuples in r to the attribute names unique to R, i.e. in the
Header of r but not in the Header of s, for which it holds that all their combinations with tuples in s are
present in r.

Example:
Relation or table "r":-

Code:
+--------+-------+
| [B]A [/B]| [B]B [/B]|
+--------+-------+
| a | 1 |
| b | 2 |
| a | 2 |
| p | 3 |
| p | 4 |
+--------+-------+

Relation or table "s":-


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Code:
+------+
| B |
+------+
| 2 |
| 3 |
+------+
Therefore, r ÷ s
Code:
+------+
| A |
+------+
| b |
| a |
| p |
+------+

Part: C (Unit-02) [Long Answer Type, 15 Marks Each]

Q. 1 Explain different Relational Set Operators.

Ans: DBMS supports relational set operators as well. The major relational set operators are union, intersection and
set difference. All of these can be implemented in DBMS using different queries.The relational set operators in
detail using given example are as follows as follows:

Student_Number Student_Name Student_Marks

1 John 95

2 Mary 80

3 Damon 57

Student_Number Student_Name Student_Marks

2 Mary 50

3 Damon 98
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

6 Matt 45

Union

Union combines two different results obtained by a query into a single result in the form of a table. However, the
results should be similar if union is to be applied on them. Union removes all duplicates, if any from the data and
only displays distinct values. If duplicate values are required in the resultant data, then UNION ALL is used.

An example of union is:

Select Student_Name from Art_Students

UNION

Select Student_Name from Dance_Students

This will display the names of all the students in the table Art_Students and Dance_Students i.e John, Mary,
Damon and Matt.

Intersection

The intersection operator gives the common data values between the two data sets that are intersected. The two
data sets that are intersected should be similar for the intersection operator to work. Intersection also removes all
duplicates before displaying the result.

An example of intersection is:

Select Student_Name from Art_Students

INTERSECT

Select Student_Name from Dance_Students

This will display the names of the students in the table Art_Students and in the table Dance_Students i.e all the
students that have taken both art and dance classes .Those are Mary and Damon in this example.

Set difference

The set difference operators takes the two sets and returns the values that are in the first set but not the second set.

An example of set difference is


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Select Student_Name from Art_Students

MINUS

Select Student_Name from Dance_Students

Q. 2 Explain different types of Joins and why it is used in DBMS.

Ans: Theta (θ) Join

Theta join combines tuples from different relations provided they satisfy the theta condition. The join condition is
denoted by the symbol θ.

Notation

R1 ⋈θ R2

R1 and R2 are relations having attributes (A1, A2, .., An) and (B1, B2,.. ,Bn) such that the attributes don’t have
anything in common, that is R1 ∩ R2 = Φ.

Theta join can use all kinds of comparison operators.

Student

SID Name Std

101 Alex 10

102 Maria 11

Subjects

Class Subject

10 Math

10 English

11 Music
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

11 Sports

Student_Detail −

STUDENT ⋈Student.Std = Subject.Class SUBJECT

Student_detail

SID Name Std Class Subject

101 Alex 10 10 Math

101 Alex 10 10 English

102 Maria 11 11 Music

102 Maria 11 11 Sports

Equijoin

When Theta join uses only equality comparison operator, it is said to be equijoin. The above example corresponds
to equijoin.

Natural Join

Natural join does no use any comparison operator. It does not concatenate the way a Cartesian product does. We
can perform a Natural Join only if there is at least one common attribute that exists between two relations. In
addition, the attributes must have the same name and domain.

Natural join acts on those matching attributes where the values of attributes in both the relations are same.

Courses

CID Course Dept

CS01 Database CS

ME01 Mechanics ME

EE01 Electronics EE
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

HoD

Dept Head

CS Alex

ME Maya

EE Mira

Courses ⋈ HoD

Dept CID Course Head

CS CS01 Database Alex

ME ME01 Mechanics Maya

EE EE01 Electronics Mira

Outer Joins

Theta Join, Equijoin, and Natural Join are called inner joins. An inner join includes only those tuples with
matching attributes and the rest are discarded in the resulting relation. Therefore, we need to use outer joins to
include all the tuples from the participating relations in the resulting relation. There are three kinds of outer joins −
left outer join, right outer join, and full outer join.

Left Outer Join(R S)

All the tuples from the Left relation, R, are included in the resulting relation. If there are tuples in R without any
matching tuple in the Right relation S, then the S-attributes of the resulting relation are made NULL.

Left

A B

100 Database

101 Mechanics

102 Electronics
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Right

A B

100 Alex

102 Maya

104 Mira

Courses HoD

A B C D

100 Database 100 Alex

101 Mechanics --- ---

102 Electronics 102 Maya

Right Outer Join: ( R S)

All the tuples from the Right relation, S, are included in the resulting relation. If there are tuples in S without any
matching tuple in R, then the R-attributes of resulting relation are made NULL.

Courses HoD

A B C D

100 Database 100 Alex

102 Electronics 102 Maya

--- --- 104 Mira

Full Outer Join: ( R S)

All the tuples from both participating relations are included in the resulting relation. If there are no matching tuples
for both relations, their respective unmatched attributes are made NULL.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Courses HoD

A B C D

100 Database 100 Alex

101 Mechanics --- ---

102 Electronics 102 Maya

--- --- 104 Mira

Q. 3 Explain the following with an example

i.) Union and Intersection in Relational Algebra

Ans: Union Operation (∪)

It performs binary union between two given relations and is defined as −

r ∪ s = { t | t ∈ r or t ∈ s}

Notation − r U s

Where r and s are either database relations or relation result set (temporary relation).

For a union operation to be valid, the following conditions must hold −

 r, and s must have the same number of attributes.


 Attribute domains must be compatible.

 Duplicate tuples are automatically eliminated.

∏ author (Books) ∪ ∏ author (Articles)

Output − Projects the names of the authors who have either written a book or an article or both.

Intersection

An intersection is defined by the symbol ∩


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

A∩B

Defines a relation consisting of a set of all tuple that are in both A and B. However, A and B must be union-
compatible.

Example:

A∩B

Table A ∩ B

column 1 column 2

1 1

ii.) Nested Queries

Ans: A Subquery or Inner query or a Nested query is a query within another SQL query and embedded within the
WHERE clause.

A subquery is used to return data that will be used in the main query as a condition to further restrict the data to be
retrieved.

Subqueries can be used with the SELECT, INSERT, UPDATE, and DELETE statements along with the operators
like =, <, >, >=, <=, IN, BETWEEN, etc.

There are a few rules that subqueries must follow −

 Subqueries must be enclosed within parentheses.


 A subquery can have only one column in the SELECT clause, unless multiple columns are in the main
query for the subquery to compare its selected columns.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

 An ORDER BY command cannot be used in a subquery, although the main query can use an ORDER BY.
The GROUP BY command can be used to perform the same function as the ORDER BY in a subquery.

 Subqueries that return more than one row can only be used with multiple value operators such as the IN
operator.

 The SELECT list cannot include any references to values that evaluate to a BLOB, ARRAY, CLOB, or
NCLOB.

 A subquery cannot be immediately enclosed in a set function.

 The BETWEEN operator cannot be used with a subquery. However, the BETWEEN operator can be used
within the subquery.

iii.) Correlated Nested Queries

Ans: A correlated subquery is evaluated once for each row processed by the parent statement. The parent
statement can be a SELECT, UPDATE, or DELETE statement.

SELECT column1, column2, ....

FROM table1 outer

WHERE column1 operator

(SELECT column1, column2

FROM table2

WHERE expr1 =

outer.expr2);

A correlated subquery is one way of reading every row in a table and comparing values in each row against related
data. It is used whenever a subquery must return a different result or set of results for each candidate row
considered by the main query. In other words, you can use a correlated subquery to answer a multipart question
whose answer depends on the value in each row processed by the parent statement.

Q. 4 What is the difference between Null value and Embedded SQL explain with an example.

Ans: The SQL NULL is the term used to represent a missing value. A NULL value in a table is a value in a field
that appears to be blank. A field with a NULL value is a field with no value. It is very important to understand that
a NULL value is different than a zero value or a field that contains spaces.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Syntax

The basic syntax of NULL while creating a table.

SQL> CREATE TABLE CUSTOMERS(

ID INT NOT NULL,

NAME VARCHAR (20) NOT NULL,

AGE INT NOT NULL,

ADDRESS CHAR (25) ,

SALARY DECIMAL (18, 2),

PRIMARY KEY (ID)

);

Here, NOT NULL signifies that column should always accept an explicit value of the given data type. There are
two columns where we did not use NOT NULL, which means these columns could be NULL.

Embedded SQL is a method of combining the computing power of a programming language and the database
manipulation capabilities of SQL. Embedded SQL statements are SQL statements written inline with the program
source code of the host language. The embedded SQL statements are parsed by an embedded SQL preprocessor
and replaced by host-languagecalls to a code library. The output from the preprocessor is then compiled by the
host compiler. This allows programmers to embed SQL statements in programs written in any number of
languages such as C/C++, COBOL and Fortran. This differs from SQL-derived programming languages that don't
go through discrete preprocessors, such as PL/SQL and T-SQL.

The SQL standards committee defined the embedded SQL standard in two steps: a formalism called Module
Language was defined, then the embedded SQL standard was derived from Module Language.

Q. 5 What is the difference between static SQL and Dynamic SQL explain in brief.

Ans: Static or Embedded SQL are SQL statements in an application that do not change at runtime and, therefore,
can be hard-coded into the application. Dynamic SQL is SQL statements that are constructed at runtime; for
example, the application may allow users to enter their own queries.

Dynamic SQL is a programming technique that enables you to build SQL statements dynamically at runtime. You
can create more general purpose, flexible applications by using dynamic SQL because the full text of a SQL
statement may be unknown at compilation.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Below mentioned are the basic differences between Static or Embedded and Dynamic or Interactive SQL:

Static (Embedded) SQL Dynamic (Interactive) SQL

In Static SQL, how database will be accessed is In Dynamic SQL, how database will be accessed is
predetermined in the embedded SQL statement. determined at run time.

It is more swift and efficient. It is less swift and efficient.

SQL statements are compiled at compile time. SQL statements are compiled at run time.

Parsing, Validation, Optimization and Generation of Parsing, Validation, Optimization and Generation of
application plan are done at compile time. application plan are done at run time.

It is generally used for situations where data is It is generally used for situations where data is
distributed uniformly. distributed non uniformly.

EXECUTE IMMEDIATE, EXECUTE and PREPARE EXECUTE IMMEDIATE, EXECUTE and


statements are not used. PREPARE statements are used.

It is less flexible. It is more flexible.

Q. 6 Explain the following:-

i.) Aggregate Operators

Ans: The aggregation operators perform mathematical operations like Average, Aggregate, Count, Max, Min and
Sum, on the numeric property of the elements in the collection.

Method Description

Aggregate Performs a custom aggregation operation on the values in the collection.

Average calculates the average of the numeric items in the collection.

Count Counts the elements in a collection.


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Method Description

LongCount Counts the elements in a collection.

Max Finds the largest value in the collection.

Min Finds the smallest value in the collection.

Sum Calculates sum of the values in the collection.

ii.) Set Comparison Operations

Ans: Comparison operator

A comparison (or relational) operator is a mathematical symbol which is used to compare two values. Comparison
operators are used in conditions that compares one expression with another. The result of a comparison can be
TRUE, FALSE, or UNKNOWN (an operator that has one or two NULL expressions returns UNKNOWN).

The following table describes different types of comparison operators -

Operator Description Operates on

= Equal to. Any compatible data types

> Greater than. Any compatible data types

< Less than. Any compatible data types

>= Greater than equal to. Any compatible data types

<= Less than equal to. Any compatible data types

<> Not equal to. Any compatible data types

Syntax :

SELECT[column_name| * |expression]<comparison operator>


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

[column_name | * | expression ]

FROM <table_name>

WHERE <expression>[comparison operator]<expression>;

Parameters:

Name Description

column_name Name of the column of a table.

* Indicates all the columns of a table.

Expression made up of a single constant, variable, scalar function, or column name and can also
expression be the pieces of a SQL query that compare values against other values or perform arithmetic
calculations.

table_name Name of the table.

comparison Equal to (=), not equal to(<>), greater than(>), less than(<), greater than or equal to (>=), less
operator than or equal to (<=).

iii.) Active Database

Ans: Active database management systems support event monitoring. They store events in event history as an
event type and time; the former represents any kind of primitive event, while the latter represents time the event
occurred. ADMSs clearly define rule semantics such as event consumption policy, event detection and coupling
modes along with instance or set oriented semantics.

A common event consumption policy includes the following parameter contexts:

 Cumulative: All instances of primitive event are consumed if a complex event occurs.
 Chronicle: Events are consumed in time order.

Recent: The latest instances of primitive events that are part of complex events are consumed in time order.

UNIT-03

Part: A (Unit-03) [Short Answer Type, 2-3 Marks Each]


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Q. 1 What is Schema?

Ans: In computer programming, a schema (pronounced SKEE-mah) is the organization or structure for a database.
The activity of data modeling leads to a schema. (The plural form is schemata. The term is from a Greek word for
"form" or "figure." Another word from the same source is "schematic.") The term is used in discussing both
relational databases and object-oriented databases. The term sometimes seems to refer to a visualization of a
structure and sometimes to a formal text-oriented description.

Q. 2. What is functional Dependency?

Ans: Functional dependency is a relationship that exists when one attribute uniquely determines another attribute.

If R is a relation with attributes X and Y, a functional dependency between the attributes is represented as X->Y,
which specifies Y is functionally dependent on X. Here X is a determinant set and Y is a dependent attribute. Each
value of X is associated with precisely one Y value.

Functional dependency in a database serves as a constraint between two sets of attributes. Defining functional
dependency is an important part of relational database design and contributes to aspect normalization.

Q. 3 What it is need to normalize a Relational Table in DBMS?

Ans: In simple words Normalization is a systematic way of ensuring that a database structure is suitable for
general-purpose querying and free of certain undesirable characteristics—insertion, update, and deletion anomalies
—that could lead to a loss of data integrity.
Normal forms in a database or the concept of Normalization makes a Relation or Table free from
insert/update/delete anomalies and saves space by removing duplicate data.

Q. 4 What is First Normal Form?

Ans: First Normal Form (1NF)

For a table to be in the First Normal Form, it should follow the following 4 rules:

1. It should only have single(atomic) valued attributes/columns.


2. Values stored in a column should be of the same domain

3. All the columns in a table should have unique names.

4. And the order in which data is stored, does not matter.

Q. 5 What is Second Normal Form?

Ans: For a table to be in the Second Normal Form,

1. It should be in the First Normal form.


2. And, it should not have Partial Dependency.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Q. 6 What is Third Normal Form?

Ans: A table is said to be in the Third Normal Form when,

1. It is in the Second Normal form.


2. And, it doesn't have Transitive Dependency.

Q. 7 What is BCNF?

Ans: Boyce and Codd Normal Form is a higher version of the Third Normal form. This form deals with certain
type of anomaly that is not handled by 3NF. A 3NF table which does not have multiple overlapping candidate keys
is said to be in BCNF. For a table to be in BCNF, following conditions must be satisfied:

 R must be in 3rd Normal Form


 and, for each functional dependency ( X → Y ), X should be a super Key.

Q. 8 What is Decomposition?

Ans: The decomposition of a relation scheme R consists of replacing the relation schema by two or more relation
schemas that each contain a subset of the attributes of R and together include all attributes in R.
Decomposition helps in eliminating some of the problems of bad design such as redundancy, inconsistencies and
anomalies.
There are two types of decomposition :

1. Lossy Decomposition
2. Lossless Join Decomposition

Q. 9. Is it compulsion to keep a table in normal forms if yes then why is it so?

Ans: An important consideration for application developers because it is incredibly difficult to stores objects in a
relational database that maintains the same information in several places

Q. 10.What are the use of Functional Dependency over Normalization?

Ans: Functional dependencies are used in the design (or redesign) of relational databases to help eliminate
redundancy (data duplication), therefore reducing the possibility of update anomalies. Redundancy is eliminated
through a process called normalization.

Part: B (Unit-03) [Subjective Type, 8-10 Marks Each]

Q. 1 What is Normalization? How its useful to design a Good Database also discuss 1NF.

Ans: Normalization of Database


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Database Normalization is a technique of organizing the data in the database. Normalization is a systematic
approach of decomposing tables to eliminate data redundancy(repetition) and undesirable characteristics like
Insertion, Update and Deletion Anamolies. It is a multi-step process that puts data into tabular form, removing
duplicated data from the relation tables.

Normalization is used for mainly two purposes,

 Eliminating reduntant(useless) data.


 Ensuring data dependencies make sense i.e data is logically stored.

Normalization can produce controlled redundancy that lets us properly link database tables. Although redundancy
in the data is not desired, sometimes controlled redundancies are introduced to meet the users’ requirements and
processing efficiency. To achieve these objectives, we take the organized approach using normalization so that
each table in the database represents only one object, all attributes are determined by only primary key of the table,
and that no data are saved in more than one table unless it is necessary.

Regardless of the approach to the design of database, normalization is applied to ensure that the tables are well
designed. As mentioned above its all about attributes and their association. In relational database design,
normalization is a systematic way of ensuring that a database structure is suitable for general-purpose querying
and free of certain undesirable characteristics insertion, updation, and deletion anomalies that could lead to a loss
of data integrity.

Normalization ensures that attributes are grouped together in such a way that there is no redundancy or at least
controlled redundancy. If we have data redundancies, then data in the database can create problems when we
update the data. Such problems can lead to data inconsistencies, data integrity issues, and data update (add, insert,
delete) anomalies. The bottom line is “each table should have only one source of data” if it is in the normal form.

First Normal Form (1NF)

For a table to be in the First Normal Form, it should follow the following 4 rules:

1. It should only have single(atomic) valued attributes/columns.


2. Values stored in a column should be of the same domain

3. All the columns in a table should have unique names.

4. And the order in which data is stored, does not matter.

Q. 2 Describe the concept of full functional dependency.

Ans: Full functional dependency(FFD)


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

The term full functional dependency (FFD) is used to indicate the minimum set of attributes in of a functional
dependency (FD). In other words, the set of attributes X will be fufunctionally dependent on the set of attributes Y
if the following conditions are satisfied:

 X is functionally dependent on Y and


 X is not functionally dependent on any subset of Y.

In relation ASSIGN of table it is true that


FD: {EMP-ID,PROJECT, PROJECT-BUDGET} -> {YRS-SPENT-BY-EMP-ON PROJECT}

The values of EMP-ID, PROJECT and PROJECT-BUDGET determine a unique value of YRS-SPENT-BY-
EMP-ON-PROJECT. However, it is not a full functional dependency because neither the EMP-ID -> YRS-
SPENT-BY-EMP-ON-PROJECT nor the PROJECT -> YRS-SPENT-BY-EMP-ON-PROJECT holds true.
In fact, it is sufficient to know only the value of a subset of {EMP-ID, PROJECT, PROJECTBUDGET), namely,
{EMP-ID, PROJECT}, to determine the YRS-SPENT-BY-EMP-ON PROJECT. Thus, the correct full functional
dependency (FFD) can be written as:
FD:{EMP-ID,PROJECT}->{YRS-SPENT-BY-EMP-ON-PROJECT}

Relation R1:BUDGET

PROJECT PROJECT-BUDGET

P1 INR 100 CR

P2 INR 150 CR

P3 INR 200 CR

P4 INR 100 CR

P5 INR 150 CR

P6 INR 300 CR

Relation R2:ASSIGN

YRS-SPENT-BY-
EMP-NO PROJECT
EMP-ON-PROJECT

106519 P1 5
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

112233 P3 2

106519 P2 5

123243 P4 10

106519 P3 3

111222 P1 4

Q. 3 Why BCNF to be considered stricter that 3NF? Explain Decomposition of non BCNF schema to BCNF.

Ans: BCNF to be considered stonger then 3NF

Almost all normal forms are defined as “a relation is in xNF if it satisfies all rules of yNF plus some extra”.
Sometimes other words are used but they mean the same. Because of this, yNF implies xNF and hence yNF is
stronger.

3NF (citing from head so forgive slight wording inaccuracies) requires that every non-key attribute is fully and
nontransitionally dependent on each candidate key. There is no such requirement for key attributes.

BCNF requires that every attribute is fully and nontransitionally dependent on each candidate key. Which can also
be phrased as: satisfies 3NF and in addition also requires that every key attribute is fully and nontransitionally
dependent on each candidate key.

The above means that every BCNF relation is also 3NF, but every 3NF relation is not necessarily BCNF. Hence
BCNF is stronger than 3NF.

Decompose R into BCNF form:


If R is not in BCNF, we decompose R into a set of relations S that are in BCNF.
This can be accomplished with a very simple algorithm:

Initialize S = {R}

While S has a relation R' that is not in BCNF do:

Pick a FD: X->Y that holds in R' and violates BCNF

Add the relation XY to S

Update R' = R'-Y

Return S
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

In your case the iterative steps are as follows:

S = {ABCDE} // Intialization S = {R}

S = {ACDE, AB} // Pick FD: A->B which violates BCNF

S = {ACE, AB, CD} // Pick FD: C->D which violates BCNF

// Return S as all relations are in BCNF

Thus R(A,B,C,D,E) is decomposed into a set of relations: R1(A,C,E), R2(A,B) and R3(C,D) that satisfies BCNF.

Q. 4 Describe functional dependency. Explain Armstrong’s axioms rules with examples.

Ans: Functional Dependency

Functional dependency (FD) is a set of constraints between two attributes in a relation. Functional dependency
says that if two tuples have same values for attributes A1, A2,..., An, then those two tuples must have to have same
values for attributes B1, B2, ..., Bn.

Functional dependency is represented by an arrow sign (→) that is, X→Y, where X functionally determines Y.
The left-hand side attributes determine the values of attributes on the right-hand side.

Armstrong's Axioms

If F is a set of functional dependencies then the closure of F, denoted as F +, is the set of all functional
dependencies logically implied by F. Armstrong's Axioms are a set of rules, that when applied repeatedly,
generates a closure of functional dependencies.

 Reflexive rule − If alpha is a set of attributes and beta is_subset_of alpha, then alpha holds beta.
 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.

 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.

Q. 5 What is decomposition. Explain Lossy and Lossless decomposition.

Ans: Decomposition in DBMS removes redundancy, anomalies and inconsistencies from a database by dividing
the table into multiple tables.

The following are the types:

Lossless Decomposition
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Decomposition is lossless if it is feasible to reconstruct relation R from decomposed tables using Joins. This is the
preferred choice. The information will not lose from the relation when decomposed. The join would result in the
same original relation.

Let us see an example:

<EmpInfo>

Emp_ID Emp_Name Emp_Age Emp_Location Dept_ID Dept_Name

E001 Jacob 29 Alabama Dpt1 Operations

E002 Henry 32 Alabama Dpt2 HR

E003 Tom 22 Texas Dpt3 Finance

Decompose the above table into two tables:

<EmpDetails>

Emp_ID Emp_Name Emp_Age Emp_Location

E001 Jacob 29 Alabama

E002 Henry 32 Alabama

E003 Tom 22 Texas

<DeptDetails>

Dept_ID Emp_ID Dept_Name

Dpt1 E001 Operations

Dpt2 E002 HR

Dpt3 E003 Finance


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Now, Natural Join is applied on the above two tables:

The result will be:

Emp_ID Emp_Name Emp_Age Emp_Location Dept_ID Dept_Name

E001 Jacob 29 Alabama Dpt1 Operations

E002 Henry 32 Alabama Dpt2 HR

E003 Tom 22 Texas Dpt3 Finance

Therefore, the above relation had lossless decomposition i.e. no loss of information.

Lossy Decomposition

As the name suggests, when a relation is decomposed into two or more relational schemas, the loss of information
is unavoidable when the original relation is retrieved.

Let us see an example:

<EmpInfo>

Emp_ID Emp_Name Emp_Age Emp_Location Dept_ID Dept_Name

E001 Jacob 29 Alabama Dpt1 Operations

E002 Henry 32 Alabama Dpt2 HR

E003 Tom 22 Texas Dpt3 Finance

Decompose the above table into two tables:

<EmpDetails>

Emp_ID Emp_Name Emp_Age Emp_Location

E001 Jacob 29 Alabama

E002 Henry 32 Alabama


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

E003 Tom 22 Texas

<DeptDetails>

Dept_ID Dept_Name

Dpt1 Operations

Dpt2 HR

Dpt3 Finance

Now, you won’t be able to join the above tables, since Emp_ID isn’t part of the DeptDetails relation.

Therefore, the above relation has lossy decomposition.

Q. 6 Explain in brief 2NF and 3NF.

Ans : Second normal form (2NF)

A table is said to be in 2NF if both the following conditions hold:

 Table is in 1NF (First normal form)


 No non-prime attribute is dependent on the proper subset of any candidate key of table.

An attribute that is not part of any candidate key is known as non-prime attribute.

Example: Suppose a school wants to store the data of teachers and the subjects they teach. They create a table that
looks like this: Since a teacher can teach more than one subjects, the table can have multiple rows for a same
teacher.

teacher_id Subject teacher_age

111 Maths 38

111 Physics 38

222 Biology 38
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

333 Physics 40

333 Chemistry 40

Candidate Keys: {teacher_id, subject}


Non prime attribute: teacher_age

The table is in 1 NF because each attribute has atomic values. However, it is not in 2NF because non prime
attribute teacher_age is dependent on teacher_id alone which is a proper subset of candidate key. This violates the
rule for 2NF as the rule says “no non-prime attribute is dependent on the proper subset of any candidate key of the
table”.

To make the table complies with 2NF we can break it in two tables like this:
teacher_details table:

teacher_id teacher_age

111 38

222 38

333 40

teacher_subject table:

teacher_id Subject

111 Maths

111 Physics

222 Biology

333 Physics
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

333 Chemistry

Now the tables comply with Second normal form (2NF).

Third Normal form (3NF)

A table design is said to be in 3NF if both the following conditions hold:

 Table must be in 2NF


 Transitive functional dependency of non-prime attribute on any super key should be removed.

An attribute that is not part of any candidate key is known as non-prime attribute.

In other words 3NF can be explained like this: A table is in 3NF if it is in 2NF and for each functional dependency
X-> Y at least one of the following conditions hold:

 X is a super key of table


 Y is a prime attribute of table

An attribute that is a part of one of the candidate keys is known as prime attribute.

Example: Suppose a company wants to store the complete address of each employee, they create a table named
employee_details that looks like this:

emp_id emp_name emp_zip emp_state emp_city emp_district

1001 John 282005 UP Agra Dayal Bagh

1002 Ajeet 222008 TN Chennai M-City

1006 Lora 282007 TN Chennai Urrapakkam

1101 Lilly 292008 UK Pauri Bhagwan

1201 Steve 222999 MP Gwalior Ratan

Super keys: {emp_id}, {emp_id, emp_name}, {emp_id, emp_name, emp_zip}…so on


CandidateKeys:{emp_id}
Non-prime attributes: all attributes except emp_id are non-prime as they are not part of any candidate keys.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Here, emp_state, emp_city & emp_district dependent on emp_zip. And, emp_zip is dependent on emp_id that
makes non-prime attributes (emp_state, emp_city & emp_district) transitively dependent on super key (emp_id).
This violates the rule of 3NF.

To make this table complies with 3NF we have to break the table into two tables to remove the transitive
dependency:

employee table:

emp_id emp_name emp_zip

1001 John 282005

1002 Ajeet 222008

1006 Lora 282007

1101 Lilly 292008

1201 Steve 222999

employee_zip table:

emp_zip emp_state emp_city emp_district

282005 UP Agra Dayal Bagh

222008 TN Chennai M-City

282007 TN Chennai Urrapakkam

292008 UK Pauri Bhagwan

222999 MP Gwalior Ratan

Part: C (Unit-03) [Long Answer Type, 15 Marks Each]

Q. 1 Take an Example of Student information within a table and justify all the normal forms.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Ans: First Normal Form (1NF)

In the first normal form, only single values are permitted at the intersection of each row and column; hence, there
are no repeating groups. To normalize a relation that contains a repeating group, remove the repeating group and
form two new relations.

The PK of the new relation is a combination of the PK of the original relation plus an attribute from the newly
created relation for unique identification.

Process for 1NF

We will use the Student_Grade_Report table below, from a School database, as our example to explain the
process for 1NF.

Student_Grade_Report (StudentNo, StudentName, Major, CourseNo, CourseName, InstructorNo,


InstructorName, InstructorLocation, Grade)

 In the Student Grade Report table, the repeating group is the course information. A student can take many
courses.
 Remove the repeating group. In this case, it’s the course information for each student.

 Identify the PK for your new table.

 The PK must uniquely identify the attribute value (StudentNo and CourseNo).

 After removing all the attributes related to the course and student, you are left with the student course table
(StudentCourse).

 The Student table (Student) is now in first normal form with the repeating group removed.

 The two new tables are shown below.

Student (StudentNo, StudentName, Major)

StudentCourse (StudentNo, CourseNo, CourseName, InstructorNo, InstructorName, InstructorLocation, Grade)

How to update 1NF anomalies

StudentCourse (StudentNo, CourseNo, CourseName, InstructorNo, InstructorName, InstructorLocation, Grade)

 To add a new course, we need a student.


 When course information needs to be updated, we may have inconsistencies.

 To delete a student, we might also delete critical information about a course.

Second Normal Form (2NF)


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

For the second normal form, the relation must first be in 1NF. The relation is automatically in 2NF if, and only if,
the PK comprises a single attribute.

If the relation has a composite PK, then each non-key attribute must be fully dependent on the entire PK and not
on a subset of the PK (i.e., there must be no partial dependency or augmentation).

Process for 2NF

To move to 2NF, a table must first be in 1NF.

 The Student table is already in 2NF because it has a single-column PK.


 When examining the Student Course table, we see that not all the attributes are fully dependent on the PK;
specifically, all course information. The only attribute that is fully dependent is grade.

 Identify the new table that contains the course information.

 Identify the PK for the new table.

 The three new tables are shown below.

Student (StudentNo, StudentName, Major)

CourseGrade (StudentNo, CourseNo, Grade)

CourseInstructor (CourseNo, CourseName, InstructorNo, InstructorName, InstructorLocation)

How to update 2NF anomalies

 When adding a new instructor, we need a course.


 Updating course information could lead to inconsistencies for instructor information.

 Deleting a course may also delete instructor information.

Third Normal Form (3NF)

To be in third normal form, the relation must be in second normal form. Also all transitive dependencies must be
removed; a non-key attribute may not be functionally dependent on another non-key attribute.

Process for 3NF

 Eliminate all dependent attributes in transitive relationship(s) from each of the tables that have a transitive
relationship.
 Create new table(s) with removed dependency.

 Check new table(s) as well as table(s) modified to make sure that each table has a determinant and that no
table contains inappropriate dependencies.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

 See the four new tables below.

Student (StudentNo, StudentName, Major)

CourseGrade (StudentNo, CourseNo, Grade)

Course (CourseNo, CourseName, InstructorNo)

Instructor (InstructorNo, InstructorName, InstructorLocation)

At this stage, there should be no anomalies in third normal form. Let’s look at the dependency diagram (Figure
12.1) for this example. The first step is to remove repeating groups, as discussed above.

Student (StudentNo, StudentName, Major)

StudentCourse (StudentNo, CourseNo, CourseName, InstructorNo, InstructorName, InstructorLocation, Grade)

To recap the normalization process for the School database, review the dependencies shown in Figure 12.1.

The abbreviations used in Figure are as follows:

 PD: partial dependency


 TD: transitive dependency

 FD: full dependency (Note: FD typically stands for functional dependency. Using FD as an abbreviation
for full dependency is only used in Figure 12.1.)

Boyce-Codd Normal Form (BCNF)

When a table has more than one candidate key, anomalies may result even though the relation is in 3NF. Boyce-
Codd normal form is a special case of 3NF. A relation is in BCNF if, and only if, every determinant is a candidate
key.

BCNF Example 1

Consider the following table (St_Maj_Adv).

Student_id Major Advisor

111 Physics Smith


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

111 Music Chan

320 Math Dobbs

671 Physics White

803 Physics Smith

Q. 2 What is Denormalization? Write its advantage and disadvantage also

Ans: Denormalization is an approach to speeding up read-oriented data retrieval performance in a relational


database, where the database administrator selectively adds back specific instances of redundant data after the data
structure has been normalized. A denormalized database should not be confused with a database that has never
been normalized.

Using normalization in SQL, a database will store different but related types of data in separate logical tables,
called relations. When a query combines data from multiple tables into a single result table, it is called a join. The
performance of such a join in the face of complex queries is often the occasion for the administrator to explore the
denormalization alternative.

Normalization vs. denormalization

Multiple joins in the same query can have a negative impact on performance. As the number of tables spawned by
the design increases, the complexity of the joins can create computing overhead that is unacceptable. Joins can be
I/O intensive, and related query execution can consume an inordinate amount of time, sometimes even crashing
applications.

With database denormalization, data designers stitch together disparate tables. This happens at the expense of a
number of data redundancies, but it can be useful for cutting down on the number of joins, and thus speeding
operations. The trade-off for the database designer lies in creating database systems that have fewer large tables or
more small tables, based on resources and requirements for interactivity of queries. The designer must also weigh
this against problems of data redundancy, especially the possibility of increased data inconsistency.

Database denormalization basics, benefits and costs.

After data has been duplicated, the database designer must take into account how multiple instances of the data
will be maintained. One way to denormalize a database is to allow the database management system to store
redundant data on disk. This has the added benefit of ensuring the consistency of redundant copies. As disk costs
have fallen over the years, such approaches have grown in popularity. Makers of relational databases have
enhanced databases to ensure better consistency when denormalization is employed.

Q. 3 What is Normalization explain its advantage and disadvantage in detail.


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Ans: Normalization is the process of organizing data in a database. This includes creating tables and establishing
relationships between those tables according to rules designed both to protect the data and to make the database
more flexible by eliminating two factors: redundancy and inconsistent dependency.
Redundant data wastes disk space and creates maintenance problems. If data that exists in more than one place
must be changed, the data must be changed in exactly the same way in all locations. A customer address change is
much easier to implement if that data is stored only in the Customers table and nowhere else in the database.
What is an "inconsistent dependency"? While it is intuitive for a user to look in the Customers table for the address
of a particular customer, it may not make sense to look there for the salary of the employee who calls on that
customer. The employee's salary is related to, or dependent on, the employee and thus should be moved to the
Employees table. Inconsistent dependencies can make data difficult to access; the path to find the data may be
missing or broken.
There are a few rules for database normalization. Each rule is called a "normal form." If the first rule is observed,
the database is said to be in "first normal form." If the first three rules are observed, the database is considered to
be in "third normal form." Although other levels of normalization are possible, third normal form is considered the
highest level necessary for most applications.
As with many formal rules and specifications, real world scenarios do not always allow for perfect compliance. In
general, normalization requires additional tables and some customers find this cumbersome. If you decide to
violate one of the first three rules of normalization, make sure that your application anticipates any problems that
could occur, such as redundant data and inconsistent dependencies.

Advantage of normalization:-

Smaller database: By dispensing with double information, you will have the capacity to diminish the general size
of the database.

Better execution:

1. Narrow tables: Having all the more adjusted tables permits your tables to have fewer sections and permits
you to fit more records for every information page.
2. Fewer records for every table mean speedier upkeep errands, for example, list remakes.

3. Only join tables that you require. More terrific general database association.

4. Information consistency inside the data

Disadvantages of normalization:-

1. Requires more joins to get the coveted effect. A crudely composed question can cut the database down
2. Maintenance overhead. The higher the level of normalization, the more stupendous the amount of tables in
the database.

3. More tables to join: By spreading out your information into more tables, you expand the need to join
tables.

4. Data model is troublesome to inquiry against: The information model is advanced for provisions, not for
specially appointed questioning.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

5. Tables hold codes rather than genuine information: Repeated information is put away as codes as opposed
to significant information. In this way, there is dependably a need to go to the search up table.

Q. 4 Consider the relation scheme R = {E, F, G, H, I, J, K, L, M, M} and the set of functional dependencies
{{E, F} -> {G}, {F} -> {I, J}, {E, H} -> {K, L}, K -> {M}, L -> {N} on R. What is the key for R?

Ans: with the smallest possible candidate key among the given examples -> {E}.
But from the Functional Dependencies we can clearly see that alone with {E} + we wont be able to get to R as
{E}+ = {E} ≠ R

Then we consider the next smallest set of keys which is {E,F}.


{E,F}+ = {E,F,G,I,J} ≠ R.

Next we consider {E, F, H}


{E, F, H}+ = {E, F, G, H, I, J, K, L, M, N}

So the ANSWER is {E, F, H}

Q. 5 In a schema with attributes A, B, C, D and E following set of functional dependencies are given
{A -> B, A -> C, CD -> E, B -> D, E -> A}

Which of the following functional dependencies is NOT implied by the above set?

A. CD -> AC
B. BD -> CD
C. BC -> CD
D. AC -> BC

Ans: Apply membership test for all the given Functional Dependencies.

1. CD→AC
CD+=CDEAB
2. BD→CD
BD+=BD

i.e. BD cannot derive CD and hence is not implied. Similarly rest two.

Q. 6 Consider a relation scheme R = (A, B, C, D, E, H) on which the following functional dependencies hold:
{A–>B, BC–> D, E–>C, D–>A}. What are the candidate keys of R?

Ans:Explanation:
If you focus on the right side of the functional dependencies you can see that E & H cannot be derived using the
left side of functional dependencies. Hence E & H will definitely be part of the candidate key. Therefore only
option (d) satisfies such condition.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

If any closure includes all attributes of a table then it becomes the candidate key. Find closure (As explained in
question 1) of AEH as below.

Closure of AEH = AEHB {A->B}

= AEHBC {E->C}

= AEHBCD {BC->D}

SO the answer is { AEH, BEH, DEH } will be the candidate key for R

UNIT-04

Part: A (Unit-04) [Short Answer Type, 2-3 Marks Each]


Q. 1 What a transaction log stores?

Ans: he transaction log stores every transaction and the changes made by those transactions to the database. This
answer gets very complicated when going into detail but generally it stores the following.

 Modification Operations
 Log sequence numbers (LSN)
 Row data. Before/After/Partial/Meta-data, depending on the operation.
 Reserved space for rollbacks

Q. 2 What is a Transaction State?


Ans: States of Transaction

A transaction must be in one of the following states:

 Active: the initial state, the transaction stays in this state while it is executing.
 Partially committed: after the final statement has been executed.
 Failed: when the normal execution can no longer proceed.
 Aborted: after the transaction has been rolled back and the database has been restored to its state prior to
the start of the transaction.
 Committed: after successful completion.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Q. 3 What is ACID stands for?


Ans: ACID stands for Atomicity, Consistency, Isolation, and Durability. It is a set of properties of database
transactions. The ACID properties of a DBMS allow safe sharing of data. Without these ACID properties,
everyday occurrences such using computer systems to buy products would be difficult and the potential for
inaccuracy would be huge.

Q. 4 What is a concurrent execution?

Ans: “concurrent execution of transaction” means multiple transactions execute/run concurrently in RDBMS with
each transaction doing its atomic unit of work for the operations encapsulated in the particular transaction. Usually
in RDBMS, the lowest level of locking is row-level locks. An update to a table’s row by a transaction needs to
have an exclusive access to the concerned row. This is how two different transactions will serialize their respective
access for update operations. Two transactions _cannot_ update the same row at same time.

Q. 5 What is the need of Serializability?


Ans: following are the steps:-
 Serializability is a concurrency scheme where the concurrent transaction is equivalent to one that executes
the transactions serially.
 A schedule is a list of transactions.

 Serial schedule defines each transaction is executed consecutively without any interference from other
transactions.
 Non-serial schedule defines the operations from a group of concurrent transactions that are interleaved.
 In non-serial schedule, if the schedule is not proper, then the problems can arise like multiple update,
uncommitted dependency and incorrect analysis.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

 The main objective of serializability is to find non-serial schedules that allow transactions to execute
concurrently without interference and produce a database state that could be produced by a serial
execution.

Q. 6 What do you mean by confliction in transaction?


Ans: Before discuss about conflict serializability, we need to understand what is important in a schedule. We need
what exactly a transaction is doing with a data item in a schedule.
In a schedule S, a transaction T1 may write (update) a new value for data item A by replacing the old value of A.
For example, you withdraw money from your account. Now your account will be updated with a new value.
In a schedule S, a transaction T2 may read the value of a data item B. For example, you check your balance in
your account.
Hence, we need to know the following things;
 The final operation involves a write/read operation?

 If they write/read, are they doing this operation with same data item or different data item?

 If the final operation is read/write on different data items by different transactions in a schedule then we
don’t need to worry about the order in which these transactions have to be executed.

If different transactions work on the same data items in a schedule in any of the conflict modes (say, Read-Write,
Write-Read, Write-Write), then we cannot execute them in any order that we like.

Q. 7 What is a view Serializability?


Ans: View Serializability
 View serializability is the another type of serializability.
 It can be derived by creating another schedule out of an existing schedule and involves the same set of
transactions.

Example : Let us assume two transactions T1 and T2 that are being serialized to create two different schedules
SH1 and SH2, where T1 and T2 want to access the same data item. Now there can be three scenarios

1. If in SH1, T1 reads the initial value of data item, then in SH2 , T1 should read the initial value of that same data
item.

2. If in SH2, T1 writes a value in the data item which is read by T2, then in SH2, T1 should write the value in the
data item before T2 reads it.

3. If in SH1, T1 performs the final write operation on that data item, then in SH2, T1 should perform the final
write operation on that data item.

If a concurrent schedule is view equivalent to a serial schedule of same transaction then it is said to be View
serializable.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Q. 8 What is Recoverable Schedules?


Ans: A recoverable schedule is one where, for each pair of Transaction T i and Tj such that Tj reads data item
previously written by Ti the commit operation of Ti appears before the commit operation Tj .

Suppose that the system allows T9 to commit immediately after execution of read(A) instruction.Thus T9 commit
before T8 does.
Now suppose that T8 fails before it commits. Since T9 has read the value of data item A written by T8 we must
abort T9 to ensure transaction Atomicity.
However, T9 has already committed and cannot be aborted.Thus we have a situation where it is impossible to
recover correctly from the failure of T8.

Q. 9 What is Cascadeless Schedules?


Ans: Cascadeless schedules

Transaction T10 writes a value of A that is read by Transaction T11. Transaction T11 writes a value of A that is
read by Transaction T12. Suppose at this point T10 fails. T10 must be rolled back, since T11 is dependent on T10,
T11 must be rolled back, T12 is dependent on T11, T12 must be rolled back. This phenomenon, in which a single
transaction failure leads to a series of transaction rollbacks is called Cascading rollback.

 Cascading rollback is undesirable, since it leads to the undoing of a significant amount of work.
 It is desirable to restrict the schedules to those where cascading rollbacks cannot occur, Such schedules are
called Cascadeless Schedules.
 Formally, a cascadeless schedule is one where for each pair of transaction Ti and Tj such that Tj reads data
item, previously written by Ti the commit operation of Ti appears before the read operation of Tj .

Q. 10 Explain the term Deadlock?

Ans: A deadlock is a condition wherein two or more tasks are waiting for each other in order to be finished but
none of the task is willing to give up the resources that other task needs. In this situation no task ever gets finished
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

and is in waiting state forever.

Part: B (Unit-04) [Subjective Type, 8-10 Marks Each]

Q. 1- What is a Transaction in DBMS. Explain various states of Transaction.

Ans: Ans: A transaction can be defined as a group of tasks. A single task is the minimum processing unit which
cannot be divided further.

Let’s take an example of a simple transaction. Suppose a bank employee transfers Rs 500 from A's account to B's
account. This very simple and small transaction involves several low-level tasks.

A’s Account

Open_Account(A)

Old_Balance = A.balance

New_Balance = Old_Balance - 500

A.balance = New_Balance

Close_Account(A)

B’s Account

Open_Account(B)

Old_Balance = B.balance
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

New_Balance = Old_Balance + 500

B.balance = New_Balance

Close_Account(B)

States of Transactions

A transaction in a database can be in one of the following states −

 Active − In this state, the transaction is being executed. This is the initial state of every transaction.
 Partially Committed − When a transaction executes its final operation, it is said to be in a partially
committed state.

 Failed − A transaction is said to be in a failed state if any of the checks made by the database recovery
system fails. A failed transaction can no longer proceed further.

 Aborted − If any of the checks fails and the transaction has reached a failed state, then the recovery
manager rolls back all its write operations on the database to bring the database back to its original state
where it was prior to the execution of the transaction. Transactions in this state are called aborted. The
database recovery module can select one of the two operations after a transaction aborts −

o Re-start the transaction

o Kill the transaction

 Committed − If a transaction executes all its operations successfully, it is said to be committed. All its
effects are now permanently established on the database system.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Q. 2- What do you mean by serializability? Discuss the conflict view serializability with suitable example.

Ans: Serializability

When multiple transactions are being executed by the operating system in a multiprogramming environment, there
are possibilities that instructions of one transactions are interleaved with some other transaction.

 Schedule − A chronological execution sequence of a transaction is called a schedule. A schedule can have
many transactions in it, each comprising of a number of instructions/tasks.
 Serial Schedule − It is a schedule in which transactions are aligned in such a way that one transaction is
executed first. When the first transaction completes its cycle, then the next transaction is executed.
Transactions are ordered one after the other. This type of schedule is called a serial schedule, as
transactions are executed in a serial manner.

In a multi-transaction environment, serial schedules are considered as a benchmark. The execution sequence of an
instruction in a transaction cannot be changed, but two transactions can have their instructions executed in a
random fashion. This execution does no harm if two transactions are mutually independent and working on
different segments of data; but in case these two transactions are working on the same data, then the results may
vary. This ever-varying result may bring the database to an inconsistent state.

To resolve this problem, we allow parallel execution of a transaction schedule, if its transactions are either
serializable or have some equivalence relation among them.

Conflict Equivalence

Two schedules would be conflicting if they have the following properties −

 Both belong to separate transactions.


 Both accesses the same data item.

 At least one of them is "write" operation.

Two schedules having multiple transactions with conflicting operations are said to be conflict equivalent if and
only if −

 Both the schedules contain the same set of Transactions.


 The order of conflicting pairs of operation is maintained in both the schedule

Q. 3. Describe Recoverable and cascade schedules.

Ans: 1. RECOVERABLE SCHEDULE


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

A recoverable schedule is one where, for each pair of Transaction Ti and Tj such that if Tj reads data item
previously written by Ti , then the commit operation of Ti appears before the commit operation Tj.

Suppose after T2 Read(x) operation, it commits. And then somehow T1 fails. So the transaction T2 must be
aborted so as to ensure atomicity. However, since T2 is commited , and can't be aborted . Hence a situation arrives
where it is impossible to recover.

And hence its necessary that Ti commits before Tj.

2. CASCADELESS SCHEDULE

Transaction T1 writes x that is read by Transaction T2. Transaction T2 writes x that is read by Transaction T3.
Suppose at this point T1 fails. T1 must be rolled back, since T2 is dependent on T1, T2 must be rolled back,and
since T3 is dependent on T2, T3 must be rolled back.

This phenomenon, in which a single transaction failure leads to a series of transaction rollbacks is called
Cascading rollback.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

 Cascading rollback is undesirable, since it leads to the undoing of a significant amount of work.
 It is desirable to restrict the schedules to those where cascading rollbacks cannot occur, Such schedules are
called Cascadeless Schedules.

 Formally, a cascadeless schedule is one where for each pair of transaction Ti and Tj such that Tj reads
data item, previously written by Ti the commit operation of Ti appears before the read operation of Tj .

Every Cascadeless schedule is also recoverable schedule.

Cascadeless Schedule Example,

Q. 4. State the properties (ACID) of Transaction.

Ans: Atomicity

All changes to data are performed as if they are a single operation. That is, all the changes are performed, or none
of them are.

For example, in an application that transfers funds from one account to another, the atomicity property ensures
that, if a debit is made successfully from one account, the corresponding credit is made to the other account.

Consistency

Data is in a consistent state when a transaction starts and when it ends.

For example, in an application that transfers funds from one account to another, the consistency property ensures
that the total value of funds in both the accounts is the same at the start and end of each transaction.

Isolation

The intermediate state of a transaction is invisible to other transactions. As a result, transactions that run
concurrently appear to be serialized.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

For example, in an application that transfers funds from one account to another, the isolation property ensures that
another transaction sees the transferred funds in one account or the other, but not in both, nor in neither.

Durability

After a transaction successfully completes, changes to data persist and are not undone, even in the event of a
system failure.

For example, in an application that transfers funds from one account to another, the durability property ensures
that the changes made to each account will not be reversed.

Q. 5. What is serializability? What is the need of serializability?

Ans: serializability When multiple transactions are being executed by the operating system in a
multiprogramming environment, there are possibilities that instructions of one transactions are interleaved with
some other transaction.

 Schedule − A chronological execution sequence of a transaction is called a schedule. A schedule can have
many transactions in it, each comprising of a number of instructions/tasks.
 Serial Schedule − It is a schedule in which transactions are aligned in such a way that one transaction is
executed first. When the first transaction completes its cycle, then the next transaction is executed.
Transactions are ordered one after the other. This type of schedule is called a serial schedule, as
transactions are executed in a serial manner.

In a multi-transaction environment, serial schedules are considered as a benchmark. The execution sequence of an
instruction in a transaction cannot be changed, but two transactions can have their instructions executed in a
random fashion. This execution does no harm if two transactions are mutually independent and working on
different segments of data; but in case these two transactions are working on the same data, then the results may
vary. This ever-varying result may bring the database to an inconsistent state.

need of serializability

As discussed in Concurrency control , serial schedules have less resource utilization and low throughput. To
improve it, two are more transactions are run concurrently. But concurrency of transactions may lead to
inconsistency in database. To avoid this, we need to check whether these concurrent schedules are serializable or
not.

Q6. What are concurrent executions? Describe issues in concurrent executions.

Ans: Multiple transactions are allowed to run concurrently in the system. Concurrent execution of database is
meant by execution of database in parallel. I.e. each transaction must behave in isolation. This means that the
concurrent execution does not result an inconsistent state. Ensuring consistency in spite of concurrent execution of
transactions requires is very complex .
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Concurrent execution of database transactions in a multi-user system means that any number of users can use the
same database at the same time. Concurrency control is needed in order to avoid inconsistencies in the database.

Here is an example of how this scenario can lead to an inconsistency:

Assume we have two users, Alice and Bob, who both have access to the same bank account. Alice wants to deposit
$100 and Bob wants to withdraw $200. Assuming there is $500 in the account, here is how the execution might
take place if they perform their actions at the same time:

1. Alice gets initial amount (x = $500)


2. Bob gets initial amount (x = $500)

3. Alice deposits $100 (x + 100) = $600

4. Bob withdraws $200 (x - 200) = $300

5. Alice saves the new balance ($600)

6. Bob saves the new balance ($300)

New balance after both actions should be $400. Now the database is in an inconsistent state.

Concurrency control can prevent inconsistencies by providing Alice with a temporary "lock" on the database until
she is done with her action.

Part: C (Unit-04) [Long Answer Type, 15 Marks Each]

Q. 1 Check whether the given schedule S is conflict serializable or not-

S : R1(A) , R2(A) , R1(B) , R2(B) , R3(B) , W1(A) , W2(B)

Ans:

Step-01:

List all the conflicting operations and determine the dependency between the transactions-

 R2(A) , W1(A) (T2 → T1)


 R1(B) , W2(B) (T1 → T2)

 R3(B) , W2(B) (T3 → T2)

Step-02:

Draw the precedence graph-


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

 Clearly, there exists a cycle in the precedence graph.


 Therefore, the given schedule S is not conflict serializable.

Q. 2 Check whether the given schedule S is conflict serializable and recoverable or not-

Ans: Checking Whether S is Conflict Serializable Or Not-

Step-01:

List all the conflicting operations and determine the dependency between the transactions-

 R2(X) , W3(X) (T2 → T3)


 R2(X) , W1(X) (T2 → T1)

 W3(X) , W1(X) (T3 → T1)

 W3(X) , R4(X) (T3 → T4)


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

 W1(X) , R4(X) (T1 → T4)

 W2(Y) , R4(Y) (T2 → T4)

Step-02:

Draw the precedence graph-

 Clearly, there exists no cycle in the precedence graph.


 Therefore, the given schedule S is conflict serializable.

Checking Whether S is Recoverable Or Not-

 Conflict serializable schedules are always recoverable.


 Therefore, the given schedule S is recoverable.

Alternatively,

 There exists no dirty read operation.


 This is because all the transactions which update the values commits immediately.

 Therefore, the given schedule S is recoverable.

 Also, S is a Cascadeless Schedule.


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Q. 3 Determine all the possible serialized schedules for the given schedule-

Ans: The given schedule S can be rewritten as-


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

This is because we are only concerned about the read and write operations taking place on the database.

Checking Whether S is Conflict Serializable Or Not-

Step-01:

List all the conflicting operations and determine the dependency between the transactions-

 R1(A) , W2(A) (T1 → T2)


 R2(A) , W1(A) (T2 → T1)

 W2(A) , W1(A) (T2 → T1)

 R2(B) , W1(B) (T2 → T1)

 R1(B) , W2(B) (T1 → T2)

 W1(B) , W2(B) (T1 → T2)

Step-02:

Draw the precedence graph-

 Clearly, there exists a cycle in the precedence graph.


 Therefore, the given schedule S is not conflict serializable.

 Thus, Number of possible serialized schedules = 0.

Q. 4 What is Scheduler and explain its functions?

Ans: Organizations have too many tasks, and manually dealing with each one can be daunting. To help you
simplify these management tasks, as well as offering a rich set of functionality for complex scheduling needs,
Oracle provides a collection of functions and procedures in the DBMS_SCHEDULER package. Collectively, these
functions are called the Scheduler, and they are callable from any PL/SQL program.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

The Scheduler enables database administrators and application developers to control when and where various tasks
take place in the database environment. These tasks can be time consuming and complicated, so using the
Scheduler can help you to improve the management and planning of these tasks. In addition, by ensuring that
many routine database tasks occur without manual intervention, you can lower operating costs, implement more
reliable routines, minimize human error, and shorten the time windows needed.

Some typical examples of using the Scheduler are:

 Database administrators can schedule and monitor recurring database maintenance jobs such as backups or
nightly data warehousing loads and extracts.
 Application developers can create programs and program libraries that end users can use to create or
monitor their own jobs. In addition to typical database jobs, you can schedule and monitor jobs that run as
part of an application suite.

Functions of Scheduler

The Scheduler provides complex enterprise scheduling functionality, which you can use to:

 Schedule job execution based on time or events

The most basic capability of a job scheduler is the ability to schedule a job to run at a particular date and time or
when a particular event occurs. The Scheduler enables you to reduce your operating costs by enabling you to
schedule execution of jobs. For example, consider the situation where a patch needs to be applied to a database
that is in production. To minimize disruptions, this task will need to be performed during non-peak hours. This can
be easily accomplished using the Scheduler. Instead of having IT personnel manually carry out this task during
non-peak hours, you can instead create a job and schedule it to run at a specified time using the Scheduler. See
"Creating Jobs" for more information.

 Schedule job processing in a way that models your business requirements

The Scheduler enables limited computing resources to be allocated appropriately among competing jobs, thus
aligning job processing with your business needs. This is accomplished in the following ways:

o Jobs that share common characteristic and behavior can be grouped into larger entities called job
classes. You can prioritize among the classes by controlling the resources allocated to each class.
This enables you to ensure that your critical jobs have priority and have enough resources to
complete. For example, if you have a critical project to load a data warehouse, then you can
combine all the data warehousing jobs into one class and give priority to it over other jobs by
allocating it a high percentage of the available resources.
o The Scheduler takes prioritization of jobs one step further, by providing you the ability to change
the prioritization based on a schedule. Because your definition of a critical job can change over
time, the Scheduler enables you to also change the priority among your jobs over that time frame.
For example, you may consider the jobs to load a data warehouse to be critical jobs during non-
peak hours but not during peak hours. In such a case, you can change the priority among the classes
by changing the resource allocated to each class. See "Creating Job Classes" and "Creating
Windows" for more information.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

o In addition to running jobs based on a time schedule, the Scheduler enables you start jobs in
response to system or business events. Your applications can detect events and then signal the
Scheduler. Depending on the type of signal sent, the Scheduler starts a specific job. An example of
using events to align your job processing with business needs is to prepare event-based jobs for
when a transaction fails, such as someone trying to withdraw more money from a bank account than
is available. In this case, you could run jobs that check for suspicious activity in this account.

 Manage and monitor jobs

There are multiple states that a job undergoes from its creation to its completion. Scheduler activity is logged and
information such as the status of the job and the last run time of the job can be easily tracked. This information is
stored in views and can be easily queried using Enterprise Manager or a SQL query. These views provide valuable
information about jobs and their execution that can help you schedule and manage your jobs better. For example, a
DBA can easily track all jobs that failed for user scott. See "Monitoring and Managing the Scheduler".

 Execute and manage jobs in a clustered environment

A cluster is a set of database instances that cooperates to perform the same task. Oracle Real Application Clusters
(RAC) provides scalability and reliability without any change to your applications. The Scheduler fully supports
execution of jobs in such a clustered environment. To balance the load on your system and for better performance,
you can also specify the database service where you want a job to run. See "Using the Scheduler in Real
Application Clusters Environments" for more information.

Q. 5 What is a transaction and Explain its properties?

Ans: A transaction can be defined as a group of tasks. A single task is the minimum processing unit which cannot
be divided further.

Let’s take an example of a simple transaction. Suppose a bank employee transfers Rs 500 from A's account to B's
account. This very simple and small transaction involves several low-level tasks.

A’s Account

Open_Account(A)

Old_Balance = A.balance

New_Balance = Old_Balance - 500

A.balance = New_Balance

Close_Account(A)

B’s Account
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Open_Account(B)

Old_Balance = B.balance

New_Balance = Old_Balance + 500

B.balance = New_Balance

Close_Account(B)

ACID Properties

A transaction is a very small unit of a program and it may contain several lowlevel tasks. A transaction in a
database system must maintain Atomicity, Consistency, Isolation, and Durability − commonly known as ACID
properties − in order to ensure accuracy, completeness, and data integrity.

 Atomicity − This property states that a transaction must be treated as an atomic unit, that is, either all of its
operations are executed or none. There must be no state in a database where a transaction is left partially
completed. States should be defined either before the execution of the transaction or after the
execution/abortion/failure of the transaction.
 Consistency − The database must remain in a consistent state after any transaction. No transaction should
have any adverse effect on the data residing in the database. If the database was in a consistent state before
the execution of a transaction, it must remain consistent after the execution of the transaction as well.

 Durability − The database should be durable enough to hold all its latest updates even if the system fails or
restarts. If a transaction updates a chunk of data in a database and commits, then the database will hold the
modified data. If a transaction commits but the system fails before the data could be written on to the disk,
then that data will be updated once the system springs back into action.

 Isolation − In a database system where more than one transaction are being executed simultaneously and
in parallel, the property of isolation states that all the transactions will be carried out and executed as if it is
the only transaction in the system. No transaction will affect the existence of any other transaction.

Q. 6 Justify Recoverable Schedules Vs Cascadeless Schedules.

Ans: Recoverability

A recoverable schedule is one where, for each pair of Transaction T i and Tj such that Tj reads data item previously
written by Ti the commit operation ofTi appears before the commit operation Tj .
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Suppose that the system allows T9 to commit immediately after execution of read(A) instruction.Thus T9 commit
before T8 does.

Now suppose that T8 fails before it commits. Since T9 has read the value of data item A written by T8 we must
abort T9 to ensure transaction Atomicity.

However, T9 has already committed and cannot be aborted.Thus we have a situation where it is impossible to
recover correctly from the failure of T8

Cascadeless schedules

Transaction T10 writes a value of A that is read by Transaction T11. Transaction T11 writes a value of A that is
read by Transaction T12. Suppose at this point T10 fails. T10 must be rolled back, since T11 is dependent on T10,
T11 must be rolled back, T12 is dependent on T11, T12 must be rolled back.

This phenomenon, in which a single transaction failure leads to a series of transaction rollbacks is called
Cascading rollback.

 a. Cascading rollback is undesirable, since it leads to the undoing of a significant amount of work.
 b. It is desirable to restrict the schedules to those where cascading rollbacks cannot occur, Such schedules
are called Cascadeless Schedules.

 c. Formally, a cascadeless schedule is one where for each pair of transaction Ti and Tj such that Tj reads
data item, previously written by Ti the commit operation of Ti appears before the read operation of Tj .

Every Cascadeless schedule is also recoverable schedule.

Cascadeless Schedule
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

UNIT-05

Part: A (Unit-05) [Short Answer Type, 2-3 Marks Each]

Q. 1 What does Protocols do in DBMS?

Ans: Protocols are managing the rules for transactions in DBMS. Various protocols like Timestamp-based
Protocols and Lock-based protocols are there in DBMS for Manage transactions. 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.

Q. 2 Define Lock-based Protocol?

Ans: Database systems equipped with lock-based protocols use a mechanism by which any transaction cannot read
or write data until it acquires an appropriate lock on it. Locks are of two kinds −

 Binary Locks − A lock on a data item can be in two states; it is either locked or unlocked.
 Shared/exclusive − This type of locking mechanism differentiates the locks based on their uses. If a lock is
acquired on a data item to perform a write operation, it is an exclusive lock. Allowing more than one
transaction to write on the same data item would lead the database into an inconsistent state. Read locks are
shared because no data value is being changed.

Q. 3 Define Timestamp-based Protocol?

Ans: he 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.

Q. 4 Define Validation-based protocols?

Ans: 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:
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

1. 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.
2. Validation phase: In this phase, the temporary variable value will be validated against the actual data to
see if it violates the serializability.

3. 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.

Finish(Ti): It contains the time when Ti finishes its write phase.

Q. 5 What is Database Failures in Transaction?

Ans: database management system is susceptible to a number of failures. In this chapter we will study the failure
types and commit protocols. In a distributed database system, failures can be broadly categorized into soft failures,
hard failures and network failures.

Soft Failure

Soft failure is the type of failure that causes the loss in volatile memory of the computer and not in the persistent
storage. Here, the information stored in the non-persistent storage like main memory, buffers, caches or registers,
is lost. They are also known as system crash. The various types of soft failures are as follows −

 Operating system failure.


 Main memory crash.

 Transaction failure or abortion.

 System generated error like integer overflow or divide-by-zero error.

 Failure of supporting software.

 Power failure.

Hard Failure

A hard failure is the type of failure that causes loss of data in the persistent or non-volatile storage like disk. Disk
failure may cause corruption of data in some disk blocks or failure of the total disk. The causes of a hard failure
are −

 Power failure.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

 Faults in media.

 Read-write malfunction.

 Corruption of information on the disk.

 Read/write head crash of disk.

Q. 6 What is Deadlock handling?

Ans: A system is in deadlock state if there exits a set of transactions such that every transaction in the set is
waiting for another transaction in the set. More precisely, there exist a set of transactions{T 0, T1 ... Tn} such that T0
is waiting for data item that T1 hold, and T1 is waiting for data item that T2 hold and so on.

There are 2 principle methods for dealing with the deadlock problem. We can use a Deadlock prevention protocol
to ensure that the system will never enter a deadlock state. Alternatively, we can allow the system to enter a
deadlock state, and then try to recover by using deadlock detection and deadlock recovery scheme.

Q. 7 What is Log-based Recovery?

Ans: 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.

Log-based recovery works as follows −

 The log file is kept on a stable storage media.


 When a transaction enters the system and starts execution, it writes a log about it.

<Tn, Start>

 When the transaction modifies an item X, it write logs as follows −

<Tn, X, V1, V2>

It reads Tn has changed the value of X, from V1 to V2.

 When the transaction finishes, it logs −

<Tn, commit>

Q. 8 What is Shadow Paging?

Ans: This is the method where all the transactions are executed in the primary memory or the shadow copy of
database. Once all the transactions completely executed, it will be updated to the database. Hence, if there is any
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

failure in the middle of transaction, it will not be reflected in the database. Database will be updated after all the
transaction is complete.

Q. 9 Define Recovery with Concurrent transactions

Ans: Until now, we considered recovery in an environment where only a single trans- action at a time is executing.
We now discuss how we can modify and extend the log-based recovery scheme to deal with multiple concurrent
transactions. Regardless of the number of concurrent transactions, the system has a single disk buffer and a single
log. All transactions share the buffer blocks. We allow immediate modification, and permit a buffer block to have
data items updated by one or more transactions.

Q. 10 What is Concurrency Control?

Ans: When more than one transactions are running simultaneously there are chances of a conflict to occur which
can leave database to an inconsistent state. To handle these conflicts we need concurrency control in DBMS,
which allows transactions to run simultaneously but handles them in such a way so that the integrity of data
remains intact.

Part: B (Unit-05) [Subjective Type, 8-10 Marks Each]

Q. 1- Explain concurrency control? What is lock based protocol?

Ans: Concurrency control is the procedure in DBMS for managing simultaneous operations without conflicting
with each another. Concurrent access is quite easy if all users are just reading data. There is no way they can
interfere with one another. Though for any practical database, would have a mix of reading and WRITE operations
and hence the concurrency is a challenge.

Concurrency control is used to address such conflicts which mostly occur with a multi-user system. It helps you to
make sure that database transactions are performed concurrently without violating the data integrity of respective
databases.

Therefore, concurrency control is a most important element for the proper functioning of a system where two or
multiple database transactions that require access to the same data, are executed simultaneously.

Lock Based Protocols –


A lock is a variable associated with a data item that describes a status of data item with respect to possible
operation that can be applied to it. They synchronize the access by concurrent transactions to the database items. It
is required in this protocol that all the data items must be accessed in a mutually exclusive manner. Let me
introduce you to two common locks which are used and some terminology followed in this protocol.

1. Shared Lock (S): also known as Read-only lock. As the name suggests it can be shared between
transactions because while holding this lock the transaction does not have the permission to update data on
the data item. S-lock is requested using lock-S instruction.
2. Exclusive Lock (X): Data item can be both read as well as written.This is Exclusive and cannot be held
simultaneously on the same data item. X-lock is requested using lock-X instruction.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Lock Compatibility Matrix –

Shared Exclusive

Shared True False

Exclusive False False

 A transaction may be granted a lock on an item if the requested lock is compatible with locks already held
on the item by other
transactions.
 Any number of transactions can hold shared locks on an item, but if any transaction holds an exclusive(X)
on the item no other transaction may hold any lock on the item.

 If a lock cannot be granted, the requesting transaction is made to wait till all incompatible locks held by
other transactions have been released. Then the lock is granted.

Upgrade / Downgrade locks : A transaction that holds a lock on an item A is allowed under certain condition to
change the lock state from one state to another.
Upgrade: A S(A) can be upgraded to X(A) if T i is the only transaction holding the S-lock on element A.
Downgrade: We may downgrade X(A) to S(A) when we feel that we no longer want to write on data-item A. As
we were holding X-lock on A, we need not check any conditions.

So, by now we are introduced with the types of locks and how to apply them. But wait, just by applying locks if
our problems could’ve been avoided then life would’ve been so simple! If you have done Process Synchronization
under OS you must be familiar with one consistent problem, starvation and Deadlock! We’ll be discussing them
shortly, but just so you know we have to apply Locks but they must follow a set of protocols to avoid such
undesirable problems. Shortly we’ll use 2-Phase Locking (2-PL) which will use the concept of Locks to avoid
deadlock. So, applying simple locking, we may not always produce Serializable results, it may lead to Deadlock
Inconsistency.

Problem With Simple Locking…

Consider the Partial Schedule:

T1 T2

1 lock-X(B)

2 read(B)
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

3 B:=B-50

4 write(B)

5 lock-S(A)

6 read(A)

7 lock-S(B)

8 lock-X(A)

9 …… ……

Q. 2- What is Time stamp based protocol? Explain validation based protocol.

Ans: 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.

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.

 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).


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

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.

Thomas' Write Rule

This rule states if TS(Ti) < W-timestamp(X), then the operation is rejected and T i is rolled back.

Time-stamp ordering rules can be modified to make the schedule view serializable.

Instead of making Ti rolled back, the 'write' operation itself is ignored.

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:

1. 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.
2. Validation phase: In this phase, the temporary variable value will be validated against the actual data to
see if it violates the serializability.

3. 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.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

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.

Finish(Ti): It contains the time when Ti finishes its write phase.

 This protocol is used to determine the time stamp for the transaction for serialization using the time stamp
of the validation phase, as it is the actual phase which determines if the transaction will commit or rollback.
 Hence TS(T) = validation(T).

 The serializability is determined during the validation process. It can't be decided in advance.

 While executing the transaction, it ensures a greater degree of concurrency and also less number of
conflicts.

 Thus it contains transactions which have less number of rollbacks.

Q. 3- What is database failure? Explain its recovery.

Ans: Types of Database Failures

There are many types of failures that can affect database processing. Some failures affect the main memory only,
while others involve secondary storage. Following are the types of failure:

 Hardware failures: Hardware failures may include memory errors, disk crashes, bad disk sectors, disk full
errors and so on. Hardware failures can also be attributed to design errors, inadequate (poor) quality control
during fabrication, overloading (use of under-capacity components) and wearout of mechanical parts.
 Software failures: Software failures may include failures related to softwares such as, operating system,
DBMS software, application programs and so o

Log-based Recovery

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.

Log-based recovery works as follows −

 The log file is kept on a stable storage media.


 When a transaction enters the system and starts execution, it writes a log about it.

<Tn, Start>
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

 When the transaction modifies an item X, it write logs as follows −

<Tn, X, V1, V2>

It reads Tn has changed the value of X, from V1 to V2.

 When the transaction finishes, it logs −

<Tn, commit>

The database can be modified using two approaches −

 Deferred database modification − All logs are written on to the stable storage and the database is updated
when a transaction commits.
 Immediate database modification − Each log follows an actual database modification. That is, the
database is modified immediately after every operation.

Recovery with Concurrent Transactions

When more than one transaction are being executed in parallel, the logs are interleaved. At the time of recovery, it
would become hard for the recovery system to backtrack all logs, and then start recovering. To ease this situation,
most modern DBMS use the concept of 'checkpoints'.

Checkpoint

Keeping and maintaining logs in real time and in real environment may fill out all the memory space available in
the system. As time passes, the log file may grow too big to be handled at all. Checkpoint is a mechanism where
all the previous logs are removed from the system and stored permanently in a storage disk. Checkpoint declares a
point before which the DBMS was in consistent state, and all the transactions were committed.

Q. 4 (A)-Explain backward and forward recovery also differentiate between them.

Ans: Transaction modifies data that are stored in a Database. Transaction must always pass ACID Test.
Transaction has to make sure the data in database remains consistence after it modifies the database. For
example: Online payment when made has to have effects on both parties. The amount must be withdrawn from
one account and must be deposited to another account. Or neither must happen. Only one of them must not happen
in any circumstances. In such a case Database has to rollback the transaction.

When recovering the database, it is must redo the effects of the previous transactions. This is called Rolling
Forward or simple Forward Recovery.

Let’s see the process of Rolling Forward or Forward Recovery:

Disk drive that was holding the data was crashed and you had backup copy that was 2 days older. Now you have to
recover the lost data. You can use your log file to roll forward all the transaction that was completed but lost due to
disk crash. This recovery process is called Rolling Forward or simple Forward Recovery.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Not all but some active transaction that didn’t complete successfully needs to rollback, when the disk drive
crashed. Such kind of rollback is called Backward Recovery.

Q. 4 (B)- What is deadlock in DBMS? Give two prevention schemes of deadlock.

Ans: In a multi-process system, deadlock is an unwanted situation that arises in a shared resource environment,
where a process indefinitely waits for a resource that is held by another process.

For example, assume a set of transactions {T0, T1, T2, ...,Tn}. T0 needs a resource X to complete its task. Resource
X is held by T1, and T1 is waiting for a resource Y, which is held by T 2. T2 is waiting for resource Z, which is held
by T0. Thus, all the processes wait for each other to release resources. In this situation, none of the processes can
finish their task. This situation is known as a deadlock.

Deadlocks are not healthy for a system. In case a system is stuck in a deadlock, the transactions involved in the
deadlock are either rolled back or restarted.

Deadlock Prevention

To prevent any deadlock situation in the system, the DBMS aggressively inspects all the operations, where
transactions are about to execute. The DBMS inspects the operations and analyzes if they can create a deadlock
situation. If it finds that a deadlock situation might occur, then that transaction is never allowed to be executed.

There are deadlock prevention schemes that use timestamp ordering mechanism of transactions in order to
predetermine a deadlock situation.

Wait-Die Scheme

In this scheme, if a transaction requests to lock a resource (data item), which is already held with a conflicting lock
by another transaction, then one of the two possibilities may occur −

 If TS(Ti) < TS(Tj) − that is Ti, which is requesting a conflicting lock, is older than T j − then Ti is allowed to
wait until the data-item is available.
 If TS(Ti) > TS(tj) − that is Ti is younger than Tj − then Ti dies. Ti is restarted later with a random delay but
with the same timestamp.

This scheme allows the older transaction to wait but kills the younger one.

Wound-Wait Scheme

In this scheme, if a transaction requests to lock a resource (data item), which is already held with conflicting lock
by some another transaction, one of the two possibilities may occur −

 If TS(Ti) < TS(Tj), then Ti forces Tj to be rolled back − that is T i wounds Tj. Tj is restarted later with a
random delay but with the same timestamp.
 If TS(Ti) > TS(Tj), then Ti is forced to wait until the resource is available.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

This scheme, allows the younger transaction to wait; but when an older transaction requests an item held by a
younger one, the older transaction forces the younger one to abort and release the item.

In both the cases, the transaction that enters the system at a later stage is aborted.

Deadlock Avoidance

Aborting a transaction is not always a practical approach. Instead, deadlock avoidance mechanisms can be used to
detect any deadlock situation in advance. Methods like "wait-for graph" are available but they are suitable for only
those systems where transactions are lightweight having fewer instances of resource. In a bulky system, deadlock
prevention techniques may work well.

Wait-for Graph

This is a simple method available to track if any deadlock situation may arise. For each transaction entering into
the system, a node is created. When a transaction T i requests for a lock on an item, say X, which is held by some
other transaction Tj, a directed edge is created from T i to Tj. If Tj releases item X, the edge between them is
dropped and Ti locks the data item.

The system maintains this wait-for graph for every transaction waiting for some data items held by others. The
system keeps checking if there's any cycle in the graph.

Here, we can use any of the two following approaches −

 First, do not allow any request for an item, which is already locked by another transaction. This is not
always feasible and may cause starvation, where a transaction indefinitely waits for a data item and can
never acquire it.
 The second option is to roll back one of the transactions. It is not always feasible to roll back the younger
transaction, as it may be important than the older one. With the help of some relative algorithm, a
transaction is chosen, which is to be aborted. This transaction is known as the victim and the process is
known as victim selection.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Q. 5- Explain the following log based recovery

1. Deffered databse modification.

Ans: Deferred Database Modification

The deferred-modification technique ensures transaction atomicity by recording all database modifications in the
log, but deferring all write operations of a transaction until the transaction partially commits (i.e., once the final
action of the transaction has been executed). Then the information in the logs is used to execute the deferred
writes. If the system crashes or if the transaction aborts, then the information in the logs is ignored.
Deferred Database Modification

The deferred-modification technique ensures transaction atomicity by recording all database modifications in the
log, but deferring all write operations of a transaction until the transaction partially commits (i.e., once the final
action of the transaction has been executed). Then the information in the logs is used to execute the deferred
writes. If the system crashes or if the transaction aborts, then the information in the logs is ignored.
Let T0 be transaction that transfers $50 from account A to account B:
T0: read (A);
A: = A-50;
Write (A);
Read (B);
B: = B + 50;
Write (B).

2. Immediate Database modification.

Ans: Immediate Database Modification

The immediate-update technique allows database modifications to be output to the database while the transaction
is still in the active state. These modifications are called uncommitted modifications. In the event of a crash or
transaction failure, the system must use the old-value field of the log records to restore the modified data items.
Transactions T0 and T1 executed one after the other in the order T0 followed by T1. The portion of the log
containing the relevant information concerning these two transactions appears in the following,
Portion of the system log corresponding to T0 and T1
< T0 start >
< T0, A, 1000, 950 >
< T0, B, 2000, 2050 >
< T0 commit >
< T1 start >
< T1, C, 700, 600 >
< T0 commit >

Q. 6- Make distinction between “shadow copy” and “shadow-paging” techniques.


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Ans: Shadow paging

 The AFIM (After Image) does not overwrite its BFIM (Before Image) but recorded at another place on the
disk. Thus, at any time a data item has AFIM and BFIM (Shadow copy of the data item) at two different
places on the disk.

X, Y: shadow copies; X’, Y’ : the current copies of data items

 To recover, it is sufficient to free the modified pages and discard the current directory. The state of the
database before transaction execution is available through the shadow directory. Database can be returned
to its previous state.
 Committing a transaction corresponds to discarding the previous shadow directory.

 Can be categorized as a NO-UNDO/NO-REDO technique for recovery

 Logs and checkpoints must be incorporated into the shadow paging technique.

 Disadvantages: complex storage management strategies, the overhead of writing shadow directories to
disk, garbage collection overhead (old pages referenced by the shadow directory)

Shadow copy scheme

It is simple, but efficient, scheme known as the shadow copy schemes. It is based on making copies of the database
called shadow copies that single transaction is active at a time. The scheme also supposes that the database is
simply a file on disk.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Atomicity and Durability of transaction can also be achieved by shadow database. In this method, all the changes
of transactions are updated in the shadow copy (duplicate copy) of the database. Once all the transaction is
complete, the DB pointer is made to point to this shadow database, making this as the new copy of the DB. The
old copy of DB is then deleted.

If there is any failure during the transaction, the pointer will be still pointing to old copy of database, and shadow
database will be deleted. If the transactions are complete then the pointer is changed to point to shadow DB, and
old DB is deleted.

As we can see in above diagram, the DB pointer is always pointing to consistent and stable database. This
mechanism assumes that there will not be any disk failure and only one transaction executing at a time so that the
shadow DB can hold the data for that transaction. It is useful if the DB is comparatively small because shadow DB
consumes same memory space as the actual DB. Hence it is not efficient for huge DBs. In addition, it cannot
handle concurrent execution of transactions. It is suitable for one transaction at a time.

Part: C (Unit-05) [Long Answer Type, 15 Marks Each]

Q.1 What are the difference concurrent control problems? Explain with examples.

Ans: Concurrency control is the process of managing simultaneous execution of transactions (such as queries,
updates, inserts, deletes and so on) in a multiprocessing database system without having them interfere with one
another.
This property of DBMS allows many transactions to access the same database at the same time without interfering
with each other.
The primary goal of concurrency is to ensure the atomicity of the execution of transactions in a multi-user
database environment. Concurrency controls mechanisms attempt to interleave (parallel) READ and WRITE
operations of multiple transactions so that the interleaved execution yields results that are identical to the results of
a serial schedule execution.

Problems of Concurrency Control :

When concurrent transactions are executed in an uncontrolled manner, several problems can occur.
The concurrency control has the following three main problems:

 Lost updates.
 Dirty read (or uncommitted data).
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

 Unrepeatable read (or inconsistent retrievals).

Lost Update Problem :

A lost update problem occurs when two transactions that access the same database items have their operations in a
way that makes the value of some database item incorrect.
In other words, if transactions T1 and T2 both read a record and then update it, the effects of the first update will
be overwritten by the second update.

Example:

Consider the situation given in figure that shows operations performed by two transaactions, Transaction- A and
Transaction- B with respect to time.

Transaction- A Time Transaction- B

----- t0 ----

Read X t1 ----

---- t2 Read X

Update X t3 ----

---- t4 Update X

---- t5 ----

At time t1 , Transactions-A reads value of X.


At time t2 , Transactions-B reads value of X.
At time t3,Transactions-A writes value of X on the basis of the value seen at time t1.
At time t4,Transactions-B writes value of X on the basis of the value seen at time t2.
So,update of Transactions-A is lost at time t4,because Transactions-B overwrites it without looking at its current
value.
Such type of problem is reffered as the Update Lost Problem, as update made by one transaction is lost here.

Dirty Read Problem :

A dirty read problem occurs when one transaction updates a database item and then the transaction fails for some
reason.The updated database item is accessed by another transaction before it is changed back to the original
value.In other words, a transaction T1 updates a record, which is read by the transaction T2.
Then T1 aborts and T2 now has values which have never formed part of the stable database.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Example:

Consider the situation given in figure :

Transaction- A Time Transaction- B

---- t0 ----

---- t1 Update X

Read X t2 ----

---- t3 Rollback

---- t4 ----

At time t1 , Transactions-B writes value of X.


At time t2 , Transactions-A reads value of X.
At time t3 , Transactions-B rollbacks.So,it changes the value of X back to that of prior to t1.
So,Transaction-A now has value which has never become part of the stable database.
Such type of problem is reffered as the Dirty Read Problem, as one transaction reads a dirty value which has not
been commited.

Inconsistent Retrievals Problem :

Unrepeatable read (or inconsistent retrievals) occurs when a transaction calculates some summary (aggregate)
function over a set of data while other transactions are updating the data.
The problem is that the transaction might read some data before they are changed and other data after they are
changed, thereby yielding inconsistent results.
In an unrepeatable read, the transaction T1 reads a record and then does some other processing during which the
transaction T2 updates the record. Now, if T1 rereads the record, the new value will be inconsistent with the
previous value.

Example:

Consider the situation given in figure that shows two transactions operating on three accounts :

Account-1 Account-2 Account-3

Balance = 200 Balance = 250 Balance = 150


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Transaction- A Time Transaction- B

----- t0 ----

Read Balance of Acc-1


sum <-- 200 t1 ----
Read Balance of Acc-2

Sum <-- Sum + 250 = 450 t2 ----

---- t3 Read Balance of Acc-3

Update Balance of Acc-3


---- t4
150 --> 150 - 50 --> 100

---- t5 Read Balance of Acc-1

Update Balance of Acc-1


---- t6
200 --> 200 + 50 --> 250

---- COMMIT
t7
Read Balance of Acc-3

Sum <-- Sum + 250 = 450 t8 ----

Transaction-A is summing all balances;while, Transaction-B is transferring an amount 50 from Account-3 to


Account-1.
Here,the result produced by Transaction-A is 550,which is incorrect. if this result is written in database, database
will be in inconsistent state, as actual sum is 600.
Here,Transaction-A has seen an inconsistent state of database, and has performed inconsistent analysis.

Q.2 Explain concurrency control with locking method. Explain with examples.

Ans: In a multiprogramming environment where multiple transactions can be executed simultaneously, it is highly
important to control the concurrency of transactions. We have concurrency control protocols to ensure atomicity,
isolation, and serializability of concurrent transactions. Concurrency control protocols can be broadly divided into
two categories −
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

 Lock based protocols


 Time stamp based protocols

Lock-based Protocols

Database systems equipped with lock-based protocols use a mechanism by which any transaction cannot read or
write data until it acquires an appropriate lock on it. Locks are of two kinds −

 Binary Locks − A lock on a data item can be in two states; it is either locked or unlocked.
 Shared/exclusive − This type of locking mechanism differentiates the locks based on their uses. If a lock is
acquired on a data item to perform a write operation, it is an exclusive lock. Allowing more than one
transaction to write on the same data item would lead the database into an inconsistent state. Read locks are
shared because no data value is being changed.

There are four types of lock protocols available −

Simplistic Lock Protocol

Simplistic lock-based protocols allow transactions to obtain a lock on every object before a 'write' operation is
performed. Transactions may unlock the data item after completing the ‘write’ operation.

Pre-claiming Lock Protocol

Pre-claiming protocols evaluate their operations and create a list of data items on which they need locks. Before
initiating an execution, the transaction requests the system for all the locks it needs beforehand. If all the locks are
granted, the transaction executes and releases all the locks when all its operations are over. If all the locks are not
granted, the transaction rolls back and waits until all the locks are granted.

Two-Phase Locking 2PL

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.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Two-phase locking has two phases, one is growing, where all the locks are being acquired by the transaction; and
the second phase is shrinking, where the locks held by the transaction are being released.

To claim an exclusive (write) lock, a transaction must first acquire a shared (read) lock and then upgrade it to an
exclusive lock.

Strict Two-Phase Locking

The first phase of Strict-2PL is same as 2PL. After acquiring all the locks in the first phase, the transaction
continues to execute normally. But in contrast to 2PL, Strict-2PL does not release a lock after using it. Strict-2PL
holds all the locks until the commit point and releases all the locks at a time.

Strict-2PL does not have cascading abort as 2PL does

Q.3 Explain concurrency control with time stamping method. Explain with examples.

Ans: In a multiprogramming environment where multiple transactions can be executed simultaneously, it is highly
important to control the concurrency of transactions. We have concurrency control protocols to ensure atomicity,
isolation, and serializability of concurrent transactions. Concurrency control protocols can be broadly divided into
two categories −

 Lock based protocols


 Time stamp based protocols

Timestamp-based Protocols
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

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.

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.

 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)


ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

 Operation rejected and Ti rolled back.

o Otherwise, operation executed.

Thomas' Write Rule

This rule states if TS(Ti) < W-timestamp(X), then the operation is rejected and T i is rolled back.

Time-stamp ordering rules can be modified to make the schedule view serializable.

Instead of making Ti rolled back, the 'write' operation itself is ignored.

Q.4 Explain concurrency control with optimistic method. Explain with examples.

Ans: The optimistic approach is based on the assumption that the majority of the database operations do not
conflict. The optimistic approach requires neither locking nor time stamping techniques. Instead, a transaction is
executed without restrictions until it is committed. Using an optimistic approach, each transaction moves through
two or three phases, referred to as read, validation, and write.

• During the read phase, the transaction reads the database, executes the needed computations, and makes the
updates to a private copy of the database values. All update operations of the transaction are recorded in a
temporary update file, which is not accessed by the remaining transactions.

• During the validation phase, the transaction is validated to ensure that the changes made will not affect the
integrity and consistency of the database. If the validation test is positive, the transaction goes to the write phase. If
the validation test is negative, the transaction is restarted and the changes are discarded.

• During the write phase, the changes are permanently applied to the database.

• The optimistic approach is acceptable for most read or query database systems that require few update
transactions.

Q.5 Explain different types of locks.

Ans: Binary Locks

A binary lock has only two states: locked (1) or unlocked (0).

If an object—that is, a database, table, page, or row—is locked by a transaction, no other transaction can use that
object. If an object is unlocked, any transaction can lock the object for its use. Every database operation requires
that the affected object be locked. As a rule, a transaction must unlock the object after its termination. Therefore,
every transaction requires a lock and unlock operation for each data item that is accessed. Such operations are
automatically managed and scheduled by the DBMS; the user does not need to be concerned about locking or
unlocking data items. (Every DBMS has a default locking mechanism. If the end user wants to override the
default, the LOCK TABLE and other SQL commands are available for that purpose.)
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

The binary locking technique is illustrated in the following table, using the lost updates problem. Note that the
lock and unlock features eliminate the lost update problem because the lock is not released until the WRITE
statement is completed. Therefore, a PROD_QOH value cannot be used until it has been properly updated.

However, binary locks are now considered too restrictive to yield optimal concurrency conditions. For example,
the DBMS will not allow two transactions to read the same database object even though neither transaction
updates the database, and therefore, no concurrency problems can occur. The concurrency conflicts occur only
when two transactions execute concurrently and one of them updates the database

Shared/Exclusive Locks:

The labels “shared” and “exclusive” indicate the nature of the lock. An exclusive lock exists when access is
reserved specifically for the transaction that locked the object. The exclusive lock must be used when the potential
for conflict exists. A shared lock exists when concurrent transactions are granted read access on the basis of a
common lock. A shared lock produces no conflict as long as all the concurrent transactions are read-only. A shared
lock is issued when a transaction wants to read data from the database and no exclusive lock is held on that data
item. An exclusive lock is issued when a transaction wants to update (write) a data item and no locks are currently
held on that data item by any other transaction. Using the shared/exclusive locking concept, a lock can have three
states: unlocked, shared (read), and exclusive (write).

As shown in the above table, two transactions conflict only when at least one of them is a Write transaction.
Because the two Read transactions can be safely executed at once, shared locks allow several Read transactions to
read the same data item concurrently.

For example

if transaction T1 has a shared lock on data item X and transaction T2 wants to read data item X, T2 may also
obtain a shared lock on data item X. If transaction T2 updates data item X, an exclusive lock is required by T2
over data item X. The exclusive lock is granted if and only if no other locks are held on the data item. Therefore, if
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

a shared or exclusive lock is already held on data item X by transaction T1, an exclusive lock cannot be granted to
transaction T2 and T2 must wait to begin until T1 commits. This condition is known as the mutual exclusive rule:
only one transaction at a time can own an exclusive lock on the same object. Although the use of shared locks
renders data access more efficient, a shared/exclusive lock schema increases the lock manager’s overhead, for
several reasons:

• The type of lock held must be known before a lock can be granted.

• Three lock operations exist: READ_LOCK (to check the type of lock), WRITE_LOCK (to issue the lock), and
UNLOCK (to release the lock).

• The schema has been enhanced to allow a lock upgrade (from shared to exclusive) and a lock downgrade (from
exclusive to shared).

Although locks prevent serious data inconsistencies, they can lead to two major problems:

• The resulting transaction schedule might not be serializable.

• The schedule might create deadlocks. A deadlock occurs when two transactions wait indefinitely for each other
to unlock data. A database deadlock, which is equivalent to traffic gridlock in a big city, is caused when two or
more transactions wait for each other to unlock data.

Fortunately, both problems can be managed: serializability is guaranteed through a locking protocol known as
two-phase locking, and deadlocks can be managed by using deadlock detection and prevention techniques. Those
techniques are examined in the next two sections.

Q.6 Explain Two-phase locking method.

Ans: 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.
ARYA INSTITUTE OF ENGINEERING & TECHNOLOGY
MODEL GUESS PAPER SOLUTION
(Containing Important Theory & Numerical Questions)
(B. Tech. 2nd year, 4th Semester 2024-2025)
4CS4-05: Database Management System

Two-phase locking has two phases, one is growing, where all the locks are being acquired by the transaction; and
the second phase is shrinking, where the locks held by the transaction are being released.

To claim an exclusive (write) lock, a transaction must first acquire a shared (read) lock and then upgrade it to an
exclusive lock.

Strict Two-Phase Locking

The first phase of Strict-2PL is same as 2PL. After acquiring all the locks in the first phase, the transaction
continues to execute normally. But in contrast to 2PL, Strict-2PL does not release a lock after using it. Strict-2PL
holds all the locks until the commit point and releases all the locks at a time.

Strict-2PL does not have cascading abort as 2PL does.

THE END

You might also like