0% found this document useful (0 votes)
17 views72 pages

DBMS

Uploaded by

vj833930
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views72 pages

DBMS

Uploaded by

vj833930
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 72

4 Sem CS and AI &DS

DBMS Imp Question

PART-A

1) What is DBMS?

Ans: -DBMS is a collection of programs that facilitates users to create and maintain a database.
In other words, DBMS provides us an interface or tool for performing different operations such
as the creation of a database, inserting data into it, deleting data from it, updating the data, etc.
DBMS is a software in which data is stored in a more secure way as compared to the file-based
system. Using DBMS, we can overcome many problems such as- data redundancy, data
inconsistency, easy access, more organized and understandable, and so on.

Q.2 What are the advantages of DBMS?

Ans:- There are many advantages of DBMS these are the following: -

Redundancy control

Restriction for unauthorized access

Provides multiple user interfaces

Provides backup and recovery

Enforces integrity constraints

Ensure data consistency

Easy accessibility

Q.3 What is RDBMS?

Ans: -RDBMS stands for Relational Database Management Systems. It is used to maintain the
data records and indices in tables. RDBMS is the form of DBMS which uses the structure to
identify and access data concerning the other piece of data in the database. RDBMS is the
system that enables you to perform different operations such as- update, insert, delete,
manipulate and administer a relational database with minimal difficulties. Most of the time
RDBMS use SQL language because it is easily understandable and is used for often.

Q.4 What do you understand by query optimization?

Ans:- Query optimization is the phase that identifies a plan for evaluation query that has the
least estimated cost. This phase comes into the picture when there are a lot of algorithms and
methods to execute the same task.

The advantages of query optimization are as follows:

 The output is provided faster


 A larger number of queries can be executed in less time
 Reduces time and space complexity.

Q.5 What do you understand by aggregation and atomicity?

Ans:-

Aggregation Atomicity
This property states that a database
This is a feature of the E-R model which modification must either follow all the rules
allows a relationship set to participate in or nothing at all. So, if one part of the
another relationship set. transaction fails, then the entire transaction
fails.

Q.6 Do we consider NULL values the same as that of blank space or zero?

Ans: -A NULL value is not at all same as that of zero or a blank space. The NULL value
represents a value which is unavailable, unknown, assigned or not applicable whereas zero is
a number and blank space is a character.
Q.7 Define a Relation Schema and a Relation.

Ans: -A Relation Schema is specified as a set of attributes. It is also known as table schema. It
defines what the name of the table is. Relation schema is known as the blueprint with the help
of which we can explain that how the data is organized into tables. This blueprint contains no
data.

A relation is specified as a set of tuples. A relation is the set of related attributes with identifying
key attributes.

Q.8 What is the Relationship?

Ans: -The Relationship is defined as an association among two or more entities. There are three
type of relationships in DBMS-

One-To-One: Here one record of any object can be related to one record of another object.

One-To-Many (many-to-one): Here one record of any object can be related to many records of
other object and vice versa.

Many-to-many: Here more than one records of an object can be related to n number of records
of another object.

Q.9 What is DDL (Data Definition Language) and DML (Data Manipulation Language)?

Ans:- Data Definition Language (DDL) is a standard for commands which defines the different
structures in a database. Most commonly DDL statements are CREATE, ALTER, and DROP.
These commands are used for updating data into the database.

Data Manipulation Language (DML) is a language that enables the user to access or manipulate
data as organized by the appropriate data model. For example- SELECT, UPDATE, INSERT,
DELETE.
Q.10 What is Relational Algebra?

Ans: - Relational Algebra is a Procedural Query Language which contains a set of operations
that take one or two relations as input and produce a new relationship. Relational algebra is the
basic set of operations for the relational model. The decisive point of relational algebra is that
it is similar to the algebra which operates on the number.

There are few fundamental operations of relational algebra:

Select and Project

Division and Rename

set difference (Union, Intersection etc.)

Q.11 What is Relational Calculus?

Ans:- Relational Calculus is a Non-procedural Query Language which uses mathematical


predicate calculus instead of algebra. Relational calculus doesn't work on mathematics
fundamentals such as algebra, differential, integration, etc. That's why it is also known as
predicate calculus.

There is two type of relational calculus:

Tuple relational calculus

Domain relational calculus

Q.12 What do you understand by the terms Entity, Entity Type, and Entity Set in DBMS?

Ans :- Entity: An entity is a real-world object having attributes, which are nothing but
characteristics of that particular object. For example, an employee can be an entity. This
particular entity can have attributes such as empid, empname, etc.

Entity Type: Entity type is nothing but a collection of entities, having the same attributes.
Generally, an entity type refers to one or more related tables in a particular database. So, you
can understand, entity type as a characteristic which uniquely identifies the entity. For example,
An employee can have attributes such as empid, empname, department, etc.

Entity Set: An entity set is the collection of all the entities of a particular entity type in a
database. For example, a set of employees, a set of companies, and a set of people can come
under an entity set.

Q.13 What is normalization?

Ans :-Normalization is a process of analysing the given relation schemas according to their
functional dependencies. It is used to minimize redundancy and also used to minimize
insertion, deletion and update distractions. Normalization is considered as an essential process
as it is used to avoid data redundancy, insertion anomaly, updation anomaly, deletion anomaly.

There most commonly used normal forms are:

First Normal Form(1NF)

Second Normal Form(2NF)

Third Normal Form(3NF)

Boyce & Codd Normal Form (BCNF)

Q.14 What is Denormalization?

Ans: - Denormalization is a part of database optimization technique. This process is used to


avoid the use of complex and costly joins. Denormalization doesn't refer to the thought of not
to normalize instead of that denormalization takes place after normalization. In this process,
firstly the redundancy of the data will be removed using normalization process than through
denormalization process we will add redundant data as per the requirement so that we can
easily avoid the costly joins.
Q.15 What is functional Dependency?

Ans :- Functional Dependency is the starting point of normalization. It exists when a relation
between two attributes allow you to determine the corresponding attribute's value uniquely.
The functional dependency is also known as database dependency and defines as the
relationship which occurs when one attribute in a relation uniquely determines another
attribute. It is written as A->B which means B is functionally dependent on A.

Q.16 What is the E-R model?

Ans :- E-R model is a short name for the Entity-Relationship model. This model is based on
the real world. It contains necessary objects (known as entities) and the relationship among
these objects. Here the primary objects are the entity, attribute of that entity, relationship set,
an attribute of that relationship set can be mapped in the form of E-R diagram.

In E-R diagram, entities are represented by rectangles, relationships are represented by


diamonds, attributes are the characteristics of entities and represented by ellipses, and data flow
is represented through a straight line.

Q.17 What are the different types of keys in the database?

Ans :- There are different types of Keys, that can be considered in a database.

Candidate Key – This is a set of attributes which can uniquely identify a table. Each table can
have more than a candidate key.

Super Key – This is a set of attributes which can uniquely identify a tuple. So, a unique
key is a super key.

Primary Key – This is a set of attributes which are used to uniquely identify every tuple.

Foreign Key – An attribute that can only take the values present as the values of some other
attribute, is the foreign key to the attribute to which it refers.
Q.18 What do you understand by functional dependency and transitive dependency in
DBMS?

Ans :- Functional Dependency: A functional dependency is a constraint that is used in


describing the relationship among different attributes in a relation.

Example: Consider a relation “A1” having attributes X and Y. The functional dependency
among these two attributes will be X -> Y, this implies that Y is functionally dependent on X.

Transitive Dependency: A transitive dependency is a constraint that can only occur in a


relation of three or more attributes.

Example: Consider a relation “A1” having attributes X, Y and Z. Now, X->Z is said to hold
transitive dependency, only if the following functional dependencies holds true:

X -> Y and Y -> Z then X -> Z .

Q.19 Explain the terms specialization and generalization

Ans :- Specialization: Specialization is a process of defining a set of subclasses of the entity


type. Here, each subclass will contain all the attributes and relationships of the parent entity.
Apart from this, the subclasses may contain additional attributes and relationships specific to
itself.

Generalization: Generalization is a process of finding relations, common attributes for a


particular set of entities; and finally defining a common superclass for them.

Q.20 What are the different integrity rules present in the DBMS?

Ans :- The different integrity rules present in DBMS are as follows:

Entity Integrity: This rule states that the value of the primary key can never be NULL. So, all
the tuples in the column identified as the primary key should have a value.

Referential Integrity: This rule states that either the value of the foreign key is NULL or it
should be the primary key of any other relation.
Q.21 What is 1NF?

Ans :- 1NF is the First Normal Form. It is the simplest type of normalization that you can
implement in a database. The primary objectives of 1NF are to:

Every column must have atomic (single value)

To Remove duplicate columns from the same table

Create separate tables for each group of related data and identify each row with a unique
column.

Q.22 What is the difference between a DELETE command and TRUNCATE command?

Ans :- DELETE command: DELETE command is used to delete rows from a table based on
the condition that we provide in a WHERE clause.

 DELETE command delete only those rows which are specified with the WHERE
clause.
 DELETE command can be rolled back.

TRUNCATE command: TRUNCATE command is used to remove all rows (complete data)
from a table. It is similar to the DELETE command with no WHERE clause.

 The TRUNCATE command removes all the rows from the table.
 The TRUNCATE command cannot be rolled back.

Q.23 What is the difference between a shared lock and exclusive lock?

Ans :- Shared lock: Shared lock is required for reading a data item. In the shared lock, many
transactions may hold a lock on the same data item. When more than one transaction is allowed
to read the data items then that is known as the shared lock.

Exclusive lock: When any transaction is about to perform the write operation, then the lock on
the data item is an exclusive lock. Because, if we allow more than one transaction then that
will lead to the inconsistency in the database.
Q.24 What are the differences between UNION and UNION ALL

Ans :-

UNION UNION ALL


Combines the result set of two or more
Combines the result of two or more SELECT
SELECT statements consisting of duplicate
statements consisting of distinct values
values
Syntax: UNION Syntax: UNION ALL
Has low performance than UNION ALL, as Has better performance than UNION, as
duplicate rows need to be removed. duplicate rows need not have to be removed.

Q.25 What are the differences between HAVING and WHERE clause?

Ans :-

HAVING WHERE
Used only with SELECT statement Used in a GROUP BY clause
Used with the GROUP BY function in a Applied to each row before they are a part of
query the GROUP BY function in a query

Q.26 Define the definition if JDBC.

Ans :- Java Database Connectivity (JDBC) is an application programming interface i.e. (API).
JDBC was released as a part of Java development Kit (JDK) 1.1. in the year 1996 by SUN
Microsoft.

It is a standard interface between any Java application and different databases. The function of
JDBC is to help the Java-based application to access different types of databases. JDBC provide
methods to query database, and it can also be used to update the database. JDBC provide JDBC
drivers that converts the request from Java application on client side to the language that
database understands.

Q.27 What is a trigger?

Ans :-Trigger is like a procedure that is automatically invoked by the DBMS in response to
specified changes to data base. Trigger is like a ‘Daemon that monitors a data base, and is
executed when the data base is modified in a way that matches the event specification. A data
base that has a set of associated triggers is called an active data base.
Q.28 Define “correlated subqueries”.

Ans:- A ‘correlated subquery’ is a sort of sub query but correlated subquery is reliant on another
query for a value that is returned. In case of execution, the sub query is executed first and then
the correlated query.

Q.29 Define Join and its types.

Ans :-Joins help in explaining the relation between different tables. They also enable you to
select data with relation to data in another table.

The various types are:

INNER JOINs: Blank rows are left in the middle while more than equal to two tables are
joined.

OUTER JOINs: Divided into Left Outer Join and Right Outer Join. Blank rows are left at
the specified side by joining tables in other side.

Q.30 What is a Database Transaction?

Ans :- A Database Transaction is a logical unit of processing in a DBMS which entails one or
more database access operation. Database transactions represent real-world events of any
enterprise.

All types of database access operation which are held between the beginning and end
transaction statements are considered as a single logical transaction in DBMS. During the
transaction the database is inconsistent. Only once the database is committed the state is
changed from one consistent state to another.

Q.31 Why do you need concurrency in Transactions?

Ans :- A database is a shared resource accessed. It is used by many users and processes
concurrently. For example, the banking system, railway, and air reservations systems, stock
market monitoring, supermarket inventory, and checkouts, etc.

A transaction is an action or series of actions that are being performed by a single user or
application program, which reads or updates the contents of the database
Q.32 Explain the Committed and Aborted State in Database Transaction.

Ans :-

Committed State

If a transaction completes the execution successfully then all the changes made in the local
memory during partially committed state are permanently stored in the database. You can
also see in the above diagram that a transaction goes from partially committed state to
committed state when everything is successful.

Aborted State

if a transaction fails during execution then the transaction goes into a failed state. The
changes made into the local memory (or buffer) are rolled back to the previous consistent
state and the transaction goes into aborted state from the failed state. Refer the diagram to
see the interaction between failed and aborted state.

Q.33 Define different types of operation in Transaction.

Ans-The main operations in a transaction are-

Read Operation

Write Operation

1. Read Operation

Read operation reads the data from the database and then stores it in the buffer in main
memory.

For example- Read(A) instruction will read the value of A from the database and will store it
in the buffer in main memory.

2. Write Operation

Write operation writes the updated data value back to the database from the buffer.

For example- Write(A) will write the updated value of A from the buffer to the database.

Q. 34 What is serializability?

 Serializability is a concurrency scheme where the concurrent transaction is equivalent


to one that executes the transactions serially.
 Serial schedule defines each transaction is executed consecutively without any
interference from other transactions. In the serial schedule, when the first transaction
completes its cycle, then the next transaction is executed.

 Non-serial schedule defines the operations from a group of concurrent transactions


that are interleaved. It contains many possible orders in which the system can execute
the individual operations of the transactions.
Q.35 Explain the types of Serializability.

Ans:1. Conflict Serializability

2. View Serializability

1. Conflict Serializability

 Conflict serializability defines two instructions of two different transactions accessing


the same data item to perform a read/write operation.

 It deals with detecting the instructions that are conflicting in any way and specifying
the order in which the instructions should execute in case there is any conflict.

2. View Serializability

1. View serializability is another type of serializability.

2. It can be derived by creating another schedule out of an existing schedule and involves
the same set of transactions.

Q.36 Mention the issues with traditional file-based systems that make DBMS a better
choice?

Ans:- The absence of indexing in a traditional file-based system leaves us with the only option
of scanning the full page and hence making the access of content tedious and super slow. The
other issue is redundancy and inconsistency as files have many duplicate and redundant data
and changing one of them makes all of them inconsistent. Accessing data is harder in traditional
file-based systems because data is unorganized in them.

Another issue is the lack of concurrency control, which leads to one operation locking the entire
page, as compared to DBMS where multiple operations can work on a single file
simultaneously.
Integrity check, data isolation, atomicity, security, etc. are some other issues with traditional
file-based systems for which DBMSs have provided some good solutions.

Q.37 Explain different languages present in DBMS.

Ans :- DDL(Data Definition Language): It contains commands which are required to define
the database.

E.g., CREATE, ALTER, DROP, TRUNCATE, RENAME, etc.

DML(Data Manipulation Language): It contains commands which are required to


manipulate the data present in the database.

E.g., SELECT, UPDATE, INSERT, DELETE, etc.

DCL(Data Control Language): It contains commands which are required to deal with the
user permissions and controls of the database system.

E.g., GRANT and REVOKE.

Q.38 What is concurrency control in DBMS?

Ans:- Concurrency control concept comes under the Transaction in database management
system (DBMS). It is a procedure in DBMS which helps us for the management of two
simultaneous processes to execute without conflicts between each other, these conflicts
occur in multi user systems.

Concurrency can simply be said to be executing multiple transactions at a time. It is required


to increase time efficiency. If many transactions try to access the same data, then
inconsistency arises. Concurrency control required to maintain consistency data.

Q.39 Explain Lock-based Protocols

Lock Based Protocols in DBMS is a mechanism in which a transaction cannot Read or Write
the data until it acquires an appropriate lock. Lock based protocols help to eliminate the
concurrency problem in DBMS for simultaneous transactions by locking or isolating a
particular transaction to a single user.
A lock is a data variable which is associated with a data item. This lock signifies that operations
that can be performed on the data item. Locks in DBMS help synchronize access to the database
items by concurrent transactions.

Q.40 Explain Growing and Shrinking Phase in Two-phase locking.

Ans:- Growing phase: In the growing phase, a new lock on the data item may be acquired by
the transaction, but none can be released.

Shrinking phase: In the shrinking phase, existing lock held by the transaction may be
released, but no new locks can be acquired.

Part -B

Q.1 What is a Database Management System and how is it different from a File System?

Ans: -Traditionally, the file system was used for data management. Data was stored in files and
users access those files directly by going at the location of the file physically. But things
become harder when the amount of data stored in the files get increased.

How will you search a file from millions of files available to you? Will you go one by one to
each file and search for your file? No. It is very tedious and next to impossible process.

File System

The file system is a traditional way of storing data where the user saves the file manually at
any location. It is an easy way to store texts, audio, video but here security is a major concern.
The options which are given by the operating system in the name of security are very limited.
Only options which we have are locks and hidden files. Also, these files are very hard to
maintain and users manually go to these locations to access these files.
Basis DBMS Approach File System Approach

Meaning DBMS is a collection of data. In The file system is a collection of data. In this
DBMS, the user is not required to system, the user has to write the procedures
write the procedures. for managing the database.

Sharing of data Due to the centralized approach, Data is distributed in many files, and it may
data sharing is easy. be of different formats, so it isn't easy to
share data.

Data DBMS gives an abstract view of The file system provides the detail of the data
Abstraction data that hides the details. representation and storage of data.

Security and DBMS provides a good It isn't easy to protect a file under the file
Protection protection mechanism. system.

Recovery DBMS provides a crash recovery The file system doesn't have a crash
Mechanism mechanism, i.e., DBMS protects mechanism, i.e., if the system crashes while
the user from system failure. entering some data, then the content of the
file will be lost.

Manipulation DBMS contains a wide variety of The file system can't efficiently store and
Techniques sophisticated techniques to retrieve the data.
store and retrieve the data.

Q.2 Explain Storage System in DBMS.

Ans: - A database system provides an ultimate view of the stored data. However, data in the
form of bits, bytes get stored in different storage devices.

Various types of storage devices that are used for accessing and storing data.

Types of Data Storage

For storing the data, there are different types of storage options available. These storage
types differ from one another as per the speed and accessibility. There are the following types
of storage devices used for storing the data:
 Primary Storage

 Secondary Storage

 Tertiary Storage

Primary Storage − The memory storage that is directly accessible to the CPU comes under this
category. CPU's internal memory (registers), fast memory (cache), and main memory (RAM)
are directly accessible to the CPU, as they are all placed on the motherboard or CPU chipset.
This storage is typically very small, ultra-fast, and volatile. Primary storage requires
continuous power supply in order to maintain its state. In case of a power failure, all its data
is lost.

Secondary Storage − Secondary storage devices are used to store data for future use or as
backup. Secondary storage includes memory devices that are not a part of the CPU chipset or
motherboard, for example, magnetic disks, optical disks (DVD, CD, etc.), hard disks, flash
drives, and magnetic tapes.

Tertiary Storage − Tertiary storage is used to store huge volumes of data. Since such storage
devices are external to the computer system, they are the slowest in speed. These storage
devices are mostly used to take the back up of an entire system. Optical disks and magnetic
tapes are widely used as tertiary storage.

Q.3 Explain the concept of Structure in DBMS with the help of Diagram.

Ans:- Database Management System (DBMS) is a software that allows access to data stored
in a database and provides an easy and effective method of –

 Defining the information.


 Storing the information.
 Manipulating the information.
 Protecting the information from system crashes or data theft.
 Differentiating access permissions for different users.
Applications: – It can be considered as a user-friendly web page where the user enters the
requests. Here he simply enters the details that he needs and presses buttons to get the data.

End User: – They are the real users of the database. They can be developers, designers,
administrators, or the actual users of the database.

DDL: – Data Definition Language (DDL) is a query fired to create database, schema, tables,
mappings, etc in the database. These are the commands used to create objects like tables,
indexes in the database for the first time. In other words, they create the structure of the
database.

DDL Compiler: – This part of the database is responsible for processing the DDL commands.
That means this compiler actually breaks down the command into machine-understandable
codes. It is also responsible for storing the metadata information like table name, space used
by it, number of columns in it, mapping information, etc.

DML Compiler: – When the user inserts, deletes, updates or retrieves the record from the
database, he will be sending requests which he understands by pressing some buttons. But
for the database to work/understand the request, it should be broken down to object code.

Query Optimizer: – When a user fires some requests, he is least bothered how it will be fired
on the database.

Storage Manager:

Storage Manager is a program that provides an interface between the data stored in the
database and the queries received. It is also known as Database Control System.
Q.4 What is Participation? explain the types of participation with the help of diagram.

Ans :- In a Relationship, Participation constraint specifies the existence of an entity when it is


related to another entity in a relationship type. It is also called minimum cardinality
constraint.

This constraint specifies the number of instances of an entity that can participate in a
relationship type.

There are two types of Participation constraint −

Total Participation

Each entity in the entity set is involved in at least one relationship in a relationship set i.e. the
number of relationships in every entity is involved is greater than 0.

Consider two entities Employee and Department related via Works_For relationship. Now,
every Employee works in at least one department therefore an Employee entity exist if it has
at least one Works_For relationship with Department entity. Thus, the participation of
Employee in Works_For is total relationship.

Total Participation is represented by double line in ER diagram.

Partial Participation

Each entity in entity set may or may not occur in at least one relationship in a relationship set.

For example: Consider two entities Employee and Department and they are related to each
other via Manages relationship. An Employee must manage a Department, he or she could be
the head of the department. But not every Employee in the company manages the
department. So, participation of employee in the Manages relationship type is partial i.e. only
a particular set of Employees will manage the Department but not all.
Q.5 Define Class Hierarchy with their types.

Ans:- Class Hierarchies: -

The ER Model has the power of expressing database entities in a conceptual hierarchical
manner. As the hierarchy goes up, it generalizes the view of entities, and as we go deep in the
hierarchy, it gives us the detail of every entity included.

Going up in this structure is called generalization, where entities are clubbed together to
represent a more generalized view. For example, a particular student named Mira can be
generalized along with all the students. The entity shall be a student, and further, the student
is a person. The reverse is called specialization where a person is a student, and that student
is Mira.

Generalization
Generalization is a bottom-up approach in which two lower level entities combine to form
a higher-level entity. In generalization, the higher-level entity can also combine with other
lower level entities to make further higher-level entity. It’s more like Superclass and
Subclass system, but the only difference is the approach, which is bottom-up. Hence,
entities are combined to form a more generalised entity, in other words, sub-classes are
combined to form a super-class.

For example, Saving and Current account types entities can be generalised and an entity with
name Account can be created, which covers both.

Specialization

Specialization is the opposite of generalization. In specialization, a group of entities is divided


into sub-groups based on their characteristics.
Specialization is opposite to Generalization. It is a top-down approach in which one higher
level entity can be broken down into two lower level entity. In specialization, a higher-level
entity may not have any lower-level entity sets, it's possible.

Aggregation

Aggregation is a process when relation between two entities is treated as a single entity.

In the diagram above, the relationship between Centre and Course together, is acting as an
Entity, which is in relationship with another entity Visitor. Now in real world, if a Visitor or a
Student visits a Coaching Centre, he/she will never enquire about the centre only or just about
the course, rather he/she will ask enquire about both.

Q.6 Differentiate between Weak and Strong entity.

Ans: - Strong Entity

A strong entity is an entity type whose existence doesn't depend on any other entity. Strong
entity types have a key attribute. The key attribute helps in identifying each entity uniquely. It
is represented by a rectangle. A relationship between two strong entities is represented by a
diamond shape. It is simply called a relationship.

For Example: Suppose we have two entity type DOCTOR and PATIENT. Entity DOCTOR
has attributes Doctor_id, Name, Salary and Qualification. Similarly, entity PATIENT has
attributes as Patient_id, Age, Contact_no, Address and P_name. Both are strong entity type as
both of them have their own key attribute. Doctor_id is the key attribute for entity DOCTOR
and Patient_id is the key attribute for entity type PATIENT. Both these entities have a
relationship which is a one-to-many relationship. Each doctor many treat more than one patient.
Here, the relationship and the entity type are connected by a single line. Also, it may be possible
that all the doctors are related to some patients. It may be possible that some doctors are not
related to any patients. So, there may or may not be total participation of a strong entity in a
relationship.

Weak Entity

Weak entity type doesn’t have a key attribute. Weak entity type can’t be identified on its own.
It depends upon some other strong entity for its distinct identity. It is represented by a double
outlined rectangle. This can be understood with real-life examples. There can be children only
if the parent exits. There can be no independent existence of children. There can be a room
only if building exits. There can be no independent existence of a room.

Example: Suppose we have two entity type EMPLOYEES and DEPENDANT (children of the
employee). The EMPLOYEE entity has attributes as Emp_id, Emp_name, Job_title, Age,
Salary, Address. And, the DEPENDANT has attributes as Name, Age and Relation. So,
Emp_id is the key attribute of the EMPLOYEES entity type. So, EMPLOYEES is a strong
entity and DEPENDANT is a weak entity.

Q.7 What is an embedded and dynamic SQL?

Ans: - Embedded / Static SQL

Embedded or Static SQL is those SQL statements that are fixed and can't be changed at runtime
in an application. These statements are compiled at the compile-time only. The benefit of using
this statement is that you know the path of execution of statements because you have the SQL
statements with you, so you can optimize your SQL query and can execute the query in the
best and fastest possible way. The way of accessing the data is predefined and these static SQL
statements are generally used on those databases that are uniformly distributed.

These statements are hardcoded in the application, so if you want to build some application in
which you need some dynamic or run-time SQL statements, then you should use the Dynamic
SQL statement.

Dynamic SQL

Dynamic SQL statements are those SQL statements that are created or executed at the run-
time. The users can execute their own query in some application. These statements are
compiled at the run-time. These kinds of SQL statements are used where there is a non-
uniformity in the data stored in the database. It is more flexible as compared to the static SQL
and can be used in some flexible applications.

Since the compilation is done at run-time, the system will know how to access the database at
run-time only. So, no proper planning for execution and optimization can be done previously.
This will reduce the performance of the system. Also, if you are taking the database query from
the user at run-time, then there are possibilities that the users might enter some wrong queries
and this is very dangerous because here you are dealing with lots and lots of data.

Q. 8 What is a Query and Subquery in DBMS?

Ans:- In simple terms, we can explain query as questions or doubts. Query means finding
information, asking questions about something, especially in order to express one's doubts
about it or to check its validity or accuracy.

A Query is used to traverse over some data may be of small or large quantity to find the needed
information.

Data is the facts and figures stored digitally or physically at a location. The data provides us
with the base on which we run or perform our query. Books in a library can be considered as
data. Information on the web can be considered as data. To look for the desired information in
this heap of data is called a query.

We perform many queries in our day to day life. Asking questions is a form of query. Searching
info on the web is a form of query. Looking for places on Map is a form of query. In each of
these examples, we are looking for the required information in different ways. For asking
questions we provide query in the form of voice while searching the web we enter keywords
while looking for places on the map we enter the location. This is called a query language. A
query language is a language which is used to specify our need in the retrieval procedures of
information.
A database query can be of two types:

SELECT Query

ACTION Query.

SELECT Query: A select query is used to retrieve data from a single table of a combination
of multiple tables.

SQL uses a SELECT statement to select, or extract, specific data based on the given base
condition.

ACTION Query: The action query is used to perform operations on the database such as
insertion, deletion, modification, alteration, etc.

This query changes the database in one way or another.

Subquery

A Subquery is a type of query which is written inside another query. A subquery becomes a
part of a larger query. A subquery is also called INNER QUERY OR NESTED QUERY. A
subquery provides data to the main query also called the parent query or outer query.

A subquery is basically a SELECT statement that is embedded in a clause of another SQL


statement. A subquery can be placed in:

SELECT clause

FROM Clause

WHERE Clause

HAVING Clause
Types of Subquery

Single row subquery

Multiple row subquery

Multiple column subquery

Correlated subquery

Q.9 What is a transaction? What are ACID properties?

Ans:- A database is used by many users and processes at the same time as it is a shared resource.
The IRCTC website is used at the same time by millions of users. Many people are concurrently
booking tickets but how is such a large database always consistent. The transactions that we
do on such websites are concurrently managed.

There are various properties through which the transactions occurring in the database are
managed. These properties are the ACID properties.

Atomicity

This property states that the transaction should either occur completely or doesn't occur at all.
The transaction should not occur partially. Each transaction is treated as a unit and the
execution is completed else the transaction is aborted. If any transaction is aborted all the
changes made are reversed back. If the transaction occurs completely then only it is committed.

Consistency

This property ensures that the integrity of the database is maintained before and after the
transaction. It ensures that when any transaction is executed then the database should move
from one consistent state to another consistent state.
Isolation

This property tells that each transaction is executed in the system such that it is the only
transaction in the system. If more than one transaction is taking place in parallel, then the
occurrence of one transaction will not affect the other transaction. If any transaction is using a
data item then it can’t be used by other transactions until the first transaction ends.

Durability

This property ensures that once the changes are made in the database these changes persist in
the database even if any system failure occurs. These changes are saved permanently in the
non-volatile memory. It is the responsibility of the recovery manager to ensure the durability
in the database.

Q.10 What is concurrent execution and what types of problem arises in DBMS?

Ans: - Concurrent Execution in DBMS

In a multi-user system, multiple users can access and use the same database at one time,
which is known as the concurrent execution of the database. It means that the same database
is executed simultaneously on a multi-user system by different users.

While working on the database transactions, there occurs the requirement of using the
database by multiple users for performing different operations, and in that case, concurrent
execution of the database is performed.

The thing is that the simultaneous execution that is performed should be done in an proper
manner and no operation should affect the other executing operations, thus maintaining the
consistency of the database.

Thus, on making the concurrent execution of the transaction operations, there occur several
challenging problems that need to be solved.

Problems with Concurrent Execution

In a database transaction, the two main operations are READ and WRITE operations. So, there
is a need to manage these two operations in the concurrent execution of the transactions as
if these operations are not performed in an proper manner, and the data may become
inconsistent.
1. Lost update problem (Write – Write conflict)

This type of problem occurs when two transactions in database access the same data item
and have their operations in an interleaved manner (i.e., concurrent execution) that makes
the value of the items incorrect hence making the database inconsistent.

Dirty Read Problems (W-R Conflict)

The dirty read problem occurs when one transaction updates an item of the database, and
somehow the transaction fails, and before the data gets rollback, the updated database item
is accessed by another transaction. There comes the Read-Write Conflict between both
transactions.

Unrepeatable Read Problem (W-R Conflict)

Also known as Inconsistent Retrievals Problem that occurs when in a transaction, two
different values are read for the same database item.

Q.11 Difference between conflict and view Serializability.

S.No. Conflict Serializability View Serializability

Two schedules are said to be Two schedules are said to be view


conflict equivalent if all the equivalent if the order of initial
conflicting operations in both the read, final write and update
schedule get executed in the operations is the same in both
same order. If a schedule is a the schedules. If a schedule is
conflict equivalent to its serial view equivalent to its serial
schedule then it is called Conflict schedule then it is called View
1. Serializable Schedule. Serializable Schedule.

If a schedule is view serializable If a schedule is conflict


then it may or may not be conflict serializable then it is also view
2. serializable. serializable schedule.

View equivalence is rather


Conflict equivalence can be easily difficult to achieve as both
achieved by reordering the transactions should perform
operations of two transactions similar actions in a similar
therefore, Conflict Serializability manner. Thus, View Serializability
3. is easy to achieve. is difficult to achieve.
S.No. Conflict Serializability View Serializability

If a transaction T1 writes a value


For a transaction T1 writing a A that no other transaction reads
value A that no one else reads (because later some other
but later some other transactions transactions say T2 writes its own
say T2 write its own value of A, value of A) W(A) can be placed in
W(A) cannot be placed under positions of the schedule where it
4. positions where it is never read. is never read.

Q.12 Testing of Serializability for the following schedule and create Precedence Graph.

Ans:- Explanation:

Read(A): In T1, no subsequent writes to A, so no new edges

Read(B): In T2, no subsequent writes to B, so no new edges

Read(C): In T3, no subsequent writes to C, so no new edges

Write(B): B is subsequently read by T3, so add edge T2 → T3

Write(C): C is subsequently read by T1, so add edge T3 → T1


Write(A): A is subsequently read by T2, so add edge T1 → T2

Write(A): In T2, no subsequent reads to A, so no new edges

Write(C): In T1, no subsequent reads to C, so no new edges

Write(B): In T3, no subsequent reads to B, so no new edges

Precedence graph for schedule S1:

The precedence graph for schedule S1 contains a cycle that's why Schedule S1 is non-
serializable.

Q.13 Explain the concept of Database Recovery and their techniques.

Ans:- Database Recovery:

The Database are prone to failures due to inconsistency, network failure, errors or any kind
of accidental damage. So, database recovery techniques are highly important to bring a
database back into a working state after a failure. There are four different recovery
techniques are available in the Database.

1. Mirroring

2. Recovery using Backups

3. Recovery using Transaction Logs

Mirroring:

Two complete copies of the database maintain on-line on different stable storage devices.
This method mostly uses in environments that require non-stop, fault-tolerant operations.

Recovery using Backups:


Backups are useful if there has been extensive damage to database. Backups are mainly two
types:

 Immediate Backup

 Archival Backup

Immediate Backup are kept in a floppy disk, hard disk or magnetic tapes. These come in handy
when a technical fault occurs in the primary database such as system failure, disk crashes,
network failure. Damage due to virus attacks repair using the immediate backup.

Archival Backup:

Archival Backups are kept in mass storage devices such as magnetic tape, CD-ROMs, Internet
Servers etc. They are very useful for recovering data after a disaster such as fire, earthquake,
flood etc. Archival Backup should be kept at a different site other than where the system is
functioning. Archival Backup at a separate place remains safe from thefts and international
destruction by user staff.

Recovery using Transaction Logs:

1. Shadow Paging

2. Log-Based Recovery

1. Shadow Paging- The idea is to maintain two-page tables during the life of a
transaction: the current page table and the shadow page table. When the transaction
starts, both tables are identical. The shadow page is never changed during the life of
the transaction. The current page is updated with each write operation. Each table
entry points to a page on the disk. When the transaction is committed, the shadow
page entry becomes a copy of the current page table entry and the disk block with the
old data is released.

If the shadow is stored in non-volatile memory and a system crash occurs, then the
shadow page table is copied to the current page table. This guarantees that the
shadow page table will point to the database pages corresponding to the state of the
database prior to any transaction that was active at the time of the crash, making
aborts automatic.

Q.14 Explain Time Stamp Protocol and also explain their advantage and disadvantage .

Ans: - Timestamp Ordering Protocol


The Timestamp Ordering Protocol is used to order the transactions based on their
Timestamps. The order of transaction is nothing but the ascending order of the transaction
creation.

The priority of the older transaction is higher that's why it executes first. To determine the
timestamp of the transaction, this protocol uses system time or logical counter.

The lock-based protocol is used to manage the order between conflicting pairs among
transactions at the execution time. But Timestamp based protocols start working as soon as
a transaction is created.

Let's assume there are two transactions T1 and T2. Suppose the transaction T1 has entered
the system at 007 times and transaction T2 has entered the system at 009 times. T1 has the
higher priority, so it executes first as it is entered the system first.

The timestamp ordering protocol also maintains the timestamp of last 'read' and 'write'
operation on a data.

Advantages:

 Schedules are serializable just like 2PL protocols

 No waiting for the transaction, which eliminates the possibility of deadlocks.

Disadvantages:

Starvation is possible if the same transaction is restarted and continually aborted.

Q,15 What is Validation Based Protocol and also explain Characteristics of Good Concurrency
Protocol.

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:

Read phase: In this phase, the transaction T is read and executed. It is used to read the value
of various data items and stores them in temporary local variables. It can perform all the write
operations on temporary variables without an update to the actual database.

Validation phase: In this phase, the temporary variable value will be validated against the
actual data to see if it violates the serializability.

Write phase: If the validation of the transaction is validated, then the temporary results are
written to the database or system otherwise the transaction is rolled back.

Characteristics of Good Concurrency Protocol


An ideal concurrency control DBMS mechanism has the following objectives:

 Must be resilient to site and communication failures.

 It allows the parallel execution of transactions to achieve maximum concurrency.

 Its storage mechanisms and computational methods should be modest to minimize


overhead.

 It must enforce some constraints on the structure of atomic actions of transactions.

Part -C

Q.1 What is a trigger? Explain their parts and types of trigger.

Ans: -Trigger is like a procedure that is automatically invoked by the DBMS in response to
specified changes to data base. Trigger is like a ‘Daemon that monitors a data base, and is
executed when the data base is modified in a way that matches the event specification. A data
base that has a set of associated triggers is called an active data base.

Syntax

create trigger Trigger_name

(before | after)

[insert | update | delete]

on [table_name]

[for each row]

[trigger_body]

Parts of a Trigger

Whenever a trigger is created, it contains the following three sequential parts:

Triggering Event or Statement: - The statements due to which a trigger occurs is called
triggering event or statement. Such statements can be DDL statements, DML statements or any
database operation, executing which gives rise to a trigger.

Trigger Restriction: - The condition or any limitation applied on the trigger is called trigger
restriction. Thus, if such a condition is TRUE then trigger occurs otherwise it does not occur.

Trigger Action: The body containing the executable statements that is to be executed when
trigger occurs that is with the execution of Triggering statement and upon evaluation of Trigger
restriction as True is called Trigger Action.
Types of Triggers

Depending upon, when a trigger is fired, it may be classified as :

1. Statement-level trigger
2. Row-level trigger
3. Before triggers
4. After triggers
5. Combination Trigger

1.Statement-level Trigger
A statement trigger is fired only for once for a DML statement irrespective of the number of
rows affected by the statement. For example, if you execute the following UPDATE command
STUDENTS table, statement trigger for UPDATE is executed only for once.

2.Row-level Trigger

A row trigger is fired once for each row that is affected by DML command. For example, if an
UPDATE command updates 100 rows then row-level trigger is fired 100 times whereas a
statement-level trigger is fired only for once.

3.Before Triggers

While defining a trigger, you can specify whether the trigger is to be fired before the command
(INSERT, DELETE, and UPDATE) is executed or after the command is executed. Before
triggers are commonly used to check the validity of the data before the action is performed.
For instance, you can use before trigger to prevent deletion of row if deletion should not be
allowed in the given case.

4.AFTER Triggers

After triggers are fired after the triggering action is completed. For example, If after trigger is
associated with INSERT command then it is fired after the row is inserted into the table.

5.Combination Trigger: Combination trigger are combination of two trigger type, Before
Statement Trigger: Trigger fire only once for each statement before the triggering DML
statement.

Before Row Trigger: Trigger fire for each and every record before the triggering DML
statement.
After Statement Trigger: Trigger fire only once for each statement after the triggering DML
statement executing. After Row Trigger: Trigger fire for each and every record after the
triggering DML statement executing.

Q.2 What is Functional Dependency? Explain Multivalued and Transitive Functional


Dependency.

Ans:- Functional Dependency (FD) is a constraint that determines the relation of one attribute
to another attribute in a Database Management System (DBMS). Functional Dependency helps
to maintain the quality of data in the database. It plays a vital role to find the difference between
good and bad database design.

A functional dependency is denoted by an arrow “→”. The functional dependency of X on Y


is represented by X → Y. Let’s understand Functional Dependency in DBMS with example.

Example:

Employee number Employee Name Salary City


1 Dana 50000 San Francisco
2 Francis 38000 London
3 Andrew 25000 Tokyo

In this example, if we know the value of Employee number, we can obtain Employee Name,
city, salary, etc. By this, we can say that the city, Employee Name, and salary are functionally
depended on Employee number.

Rules of Functional Dependencies

Below are the Three most important rules for Functional Dependency in Database:

Reflexive rule –. If X is a set of attributes and Y is_subset_of X, then X holds a value of Y.

Augmentation rule: When x -> y holds, and c is attribute set, then ac -> bc also holds. That is
adding attributes which do not change the basic dependencies.

1. Multivalued functional dependency

2. Transitive functional dependency

1. Multivalued Functional Dependency

Multivalued dependency occurs in the situation where there are multiple independent
multivalued attributes in a single table. A multivalued dependency is a complete constraint
between two sets of attributes in a relation. It requires that certain tuples be present in a
relation.
In Multivalued functional dependency, entities of the dependent set are not dependent on
each other.
i.e. If a → {b, c} and there exists no functional dependency between b and c, then it is called
a multivalued functional dependency.
For example,

roll_no name age

42 abc 17

43 pqr 18

44 xyz 18

Here, roll_no → {name, age} is a multivalued functional dependency,

2. Transitive Functional Dependency


In transitive functional dependency, dependent is indirectly dependent on determinant.
i.e. If a → b & b → c, then according to axiom of transitivity, a → c. This is a transitive
functional dependency.

For example,

Enrol_ building
no name dept no

42 abc CO 4

43 pqr EC 2

44 xyz IT 1

45 abc EC 2

Here, enrol_no → dept and dept → building_no,


Hence, according to the axiom of transitivity, enrol_no → building_no is a valid
functional dependency. This is an indirect functional dependency, hence called
Transitive functional dependency.
Q,3 Explain the concept of NULL? also explain their important and define Where is
NULL and NOT NULL in DBMS.

Ans: In SQL there may be some records in a table that do not have values or data for every
field. This could be possible because at a time of data entry information is not available. So
SQL supports a special value known as NULL which is used to represent the values of attributes
that may be unknown or not apply to a tuple. SQL places a NULL value in the field in the
absence of a user-defined value.

For example, the Apartment_number attribute of an address applies only to address that are in
apartment buildings and not to other types of residences.

Importance of NULL value

 It is important to understand that a NULL value is different from a zero value.

 A NULL value is used to represent a missing value, but that it usually has one of three
different interpretations:

 The value unknown (value exists but is not known)

 Value not available (exists but is purposely withheld)

 Attribute not applicable (undefined for this tuple)

 It is often not possible to determine which of the meanings is intended. Hence, SQL
does not distinguish between the different meanings of NULL.

Where SQL is NULL

There is an example of student table:

SURNAME NAME MARKS

TYAGI SEEMA

SINGH RAMAN 5

SHARMA AMAR

JAISWAL VICKY 6
SELECT SURNAME, NAME, MARKS FROM STUDENTS

WHERE MARKS IS NULL;

It will return the following records:

SURNAME NAME MARKS

SHARMA AMAR

TYAGI SEEMA

Where SQL is NOT NULL

How to select records with no null values (in marks column)? Let's see the query to get all the
records where marks is NOT NULL

SELECT SIR_NAME, FIRSTNAME, MARKS FROM STUDENTS

WHERE MARKS IS NOT NULL ;

SURNAME NAME MARKS

SINGH RAMAN 5

JAISWAL VICKY 6

Q.5 What is Relational Decomposition? explain their types with example.

Ans: Relational Decomposition

When a relation in the relational model is not in appropriate normal form then the
decomposition of a relation is required.

In a database, it breaks the table into multiple tables. If the relation has no proper
decomposition, then it may lead to problems like loss of information. Decomposition is used
to eliminate some of the problems of bad design like anomalies, inconsistencies, and
redundancy.
Types of Decomposition

Lossless Decomposition

 If the information is not lost from the relation that is decomposed, then the
decomposition will be lossless.

 The lossless decomposition guarantees that the join of relations will result in the same
relation as it was decomposed.

 The relation is said to be lossless decomposition if natural joins of all the


decomposition give the original relation.

EMPLOYEE_DEPARTMENT table:

EMP_ID EMP_NAME EMP_AGE EMP_CITY DEPT_ID DEPT_NAME


22 Denim 28 Mumbai 827 Sales
33 Alina 25 Delhi 438 Marketing
46 Stephan 30 Bangalore 869 Finance
52 Katherine 36 Mumbai 575 Production
60 Jack 40 Noida 678 Testing

The above relation is decomposed into two relations EMPLOYEE and DEPARTMENT

EMPLOYEE table:

EMP_ID EMP_NAME EMP_AGE EMP_CITY


22 Denim 28 Mumbai
33 Alina 25 Delhi
46 Stephan 30 Bangalore
52 Katherine 36 Mumbai
60 Jack 40 Noida

DEPARTMENT table

DEPT_ID EMP_ID DEPT_NAME


827 22 Sales
438 33 Marketing
869 46 Finance
575 52 Production
678 60 Testing

Now, when these two relations are joined on the common column "EMP_ID", then the
resultant relation will look like:

Employee ⋈ Department

EMP_ID EMP_NAME EMP_AGE EMP_CITY DEPT_ID DEPT_NAME

22 Denim 28 Mumbai 827 Sales

33 Alina 25 Delhi 438 Marketing

46 Stephan 30 Bangalore 869 Finance

52 Katherine 36 Mumbai 575 Production

60 Jack 40 Noida 678 Testing


Hence, the decomposition is Lossless join decomposition.

Dependency Preserving

 It is an important constraint of the database.

 In the dependency preservation, at least one decomposed table must satisfy every
dependency.

 If a relation R is decomposed into relation R1 and R2, then the dependencies of R


either must be a part of R1 or R2 or must be derivable from the combination of
functional dependencies of R1 and R2.

 For example, suppose there is a relation R (A, B, C, D) with functional dependency set
(A->BC). The relational R is decomposed into R1(ABC) and R2(AD) which is dependency
preserving because FD A->BC is a part of relation R1(ABC).

A B C

1 2 1

2 5 3

3 3 3

R (A, B, C)

 Consider this relation is decomposed into two sub relations as R1(A, C) and R2(B,
C )-

 The two sub relations are-


R1( A , C ) R2(B , C )
A C B C

1 1 2 1

2 3 5 3

3 3 3 3

 Now, let us check whether this decomposition is lossy or not.


 For lossy decomposition, we must have-
R1 ⋈ R2 ⊃ R
 Now, if we perform the natural join ( ⋈ ) of the sub relations R1 and R2 we get-

A B C

1 2 1

2 5 3

2 3 3

3 5 3

3 3 3

Q.6 Explain the fourth and fifth Normal Form in DBMS with example.

Ans : Fourth normal form (4NF)

• A relation will be in 4NF if it is in Boyce Codd normal form and has no multi-valued
dependency.
• For a dependency A → B, if for a single value of A, multiple values of B exist, then the
relation will be a multi-valued dependency.

Multivalued Dependency

Multivalued dependency occurs when two attributes in a table are independent of each other
but, both depend on a third attribute.

A multivalued dependency consists of at least two attributes that are dependent on a third
attribute that's why it always requires at least three attributes.

Example: Suppose there is a bike manufacturer company which produces two colors (white
and black) of each model every year.

BIKE_MODEL MANUF_YEAR COLOR

M2011 2008 White

M2001 2008 Black

M3001 2013 White

M3001 2013 Black

M4006 2017 White

M4006 2017 Black

• Here columns COLOR and MANUF_YEAR are dependent on BIKE_MODEL and


independent of each other.

• In this case, these two columns can be called as multivalued dependent on


BIKE_MODEL. The representation of these dependencies is shown below:

• BIKE_MODEL → → MANUF_YEAR

• BIKE_MODEL → → COLOR

• This can be read as "BIKE_MODEL multidetermined MANUF_YEAR" and "BIKE_MODEL


multidetermined COLOR".
Example: student
STU_ID COURSE HOBBY

21 Computer Dancing

21 Math Singing

34 Chemistry Dancing

74 Biology Cricket

59 Physics Hockey

• The given STUDENT table is in 3NF, but the COURSE and HOBBY are two independent
entity. Hence, there is no relationship between COURSE and HOBBY.

• In the STUDENT relation, a student with STU_ID, 21 contains two


courses, Computer and Math and two hobbies, Dancing and Singing. So there is a
Multi-valued dependency on STU_ID, which leads to unnecessary repetition of data.

So to make the above table into 4NF, we can decompose it into two tables:

STUDENT_COURSE

STU_ID COURSE

21 Computer

21 Math

34 Chemistry

74 Biology

59 Physics

STUDENT_HOBBY

STU_ID HOBBY
21 Dancing

21 Singing

34 Dancing

74 Cricket

59 Hockey

Join Dependency

Joint dependency – Join decomposition is a further generalization of Multivalued


dependencies.

If the join of R1 and R2 over C is equal to relation R then we can say that a join dependency
(JD) exists, where R1 and R2 are the decomposition R1(A, B, C) and R2(C, D) of a given relations
R (A, B, C, D).

Alternatively, R1 and R2 are a lossless decomposition of R

Example – Table R1 Table R2

COMPANY PRODUCT AGENT COMPANY

C1 pen drive Aman C1

C1 mic Aman C2

C2 speaker Mohan C1

C2 speaker
Agent->->Company Company ->->Product

Table R3

AGENT PRODUCT

Aman pendrive

Aman mic

speaker
Aman

Mohan speaker

Agent->->Product

Table – R1⋈R2⋈R3

COMPANY PRODUCT AGENT

C1 pen drive Aman

C1 mic Aman

C2 speaker speaker

C1 speaker Aman

Fifth Normal Form / Projected Normal Form (5NF):-

• A relation R is in 5NF if and only if every join dependency in R is implied by the


candidate keys of R.

• A relation decomposed into two relations must have loss-less join Property, which
ensures that no spurious or extra tuples are generated, when relations are reunited
through a natural join.

• Properties – A relation R is in 5NF if and only if it satisfies following conditions:

• R should be already in 4NF.

• It cannot be further non loss decomposed (join dependency).

Example – Consider the above schema, with a case as “if a company makes a product
and an agent is an agent for that company, then he always sells that product for the
company”. Under these circumstances, the ACP table is shown as:

Table – ACP

AGENT COMPANY PRODUCT

A1 PQR Nut

A1 PQR Bolt
A1 XYZ Nut

A1 XYZ Bolt

A2 PQR Nut

The relation ACP is again decompose into 3 relations. Now, the natural Join of all the
three relations will be shown as:

Table – R1 Table- R2

AGENT COMPANY AGENT PRODUCT


A1 PQR A1 Nut
A1 XYZ A1 Bolt
A2 PQR A2 Nut

Table – R3

COMPANY PRODUCT

PQR Nut

PQR Bolt

XYZ Nut

XYZ Bolt

• Result of Natural Join of R1 and R3 over ‘Company’ and then Natural Join of R13 and
R2 over ‘Agent ‘and ‘Product’ will be table ACP.
• Hence, in this example, all the redundancies are eliminated, and the decomposition of
ACP is a lossless join decomposition.

• Therefore, the relation is in 5NF as it does not violate the property of lossless join.

Q.7 Explain the ACID Property in Transaction Database .

Ans:- ACID Properties in DBMS

DBMS is the management of data that should remain integrated when any changes are done
in it. It is because if the integrity of the data is affected, whole data will get disturbed and
corrupted.

Therefore, to maintain the integrity of the data, there are four properties described in the
database management system, which are known as the ACID properties. The ACID properties
are meant for the transaction that goes through a different group of tasks.

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

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

Durability

In DBMS, the term durability ensures that the data after the successful execution of the
operation becomes permanent in the database. The durability of the data should be so
perfect that even if the system fails or leads to a crash, the database still survives. However,
if gets lost, it becomes the responsibility of the recovery manager for ensuring the durability
of the database. For committing the values, the COMMIT command must be used every time
we make changes.

Therefore, the ACID property of DBMS plays a vital role in maintaining the consistency and
availability of data in the database.

Operations in Transaction-

The main operations in a transaction are-

Read Operation

Write Operation

1. Read Operation

Read operation reads the data from the database and then stores it in the buffer in main
memory.

For example- Read(A) instruction will read the value of A from the database and will store it
in the buffer in main memory.

2. Write Operation

Write operation writes the updated data value back to the database from the buffer.

For example- Write(A) will write the updated value of A from the buffer to the database.
Q.8 What is a Database Transaction? Why do you need concurrency in Transactions?

and explain each state of Transaction in DBMS.

Ans :- A database is a shared resource accessed. It is used by many users and processes
concurrently. For example, the banking system, railway, and air reservations systems, stock
market monitoring, supermarket inventory, and checkouts, etc.

A transaction is an action or series of actions that are being performed by a single user or
application program, which reads or updates the contents of the database.

States of Transaction

In a database, the transaction can be in one of the following states –

Active State

As we have discussed in the DBMS transaction introduction that a transaction is a sequence


of operations. If a transaction is in execution then it is said to be in active state. It doesn’t
matter which step is in execution, until unless the transaction is executing, it remains in active
state.

Failed State
If a transaction is executing and a failure occurs, either a hardware failure or a software failure
then the transaction goes into failed state from the active state.

Partially Committed State

a transaction goes into “partially committed” state from the active state when there are read
and write operations present in the transaction.

A transaction contains number of read and write operations. Once the whole transaction is
successfully executed, the transaction goes into partially committed state where we have all
the read and write operations performed on the main memory (local memory) instead of the
actual database.

The reason why we have this state is because a transaction can fail during execution so if we
are making the changes in the actual database instead of local memory, database may be left
in an inconsistent state in case of any failure.

Committed State

If a transaction completes the execution successfully then all the changes made in the local
memory during partially committed state are permanently stored in the database. You can
also see in the above diagram that a transaction goes from partially committed state to
committed state when everything is successful.

Aborted State

if a transaction fails during execution then the transaction goes into a failed state. The
changes made into the local memory (or buffer) are rolled back to the previous consistent
state and the transaction goes into aborted state from the failed state. Refer the diagram to
see the interaction between failed and aborted state.

Q.9 Explain Schedule in DBMS and explain Recoverable & Non Recoverable Schedule in
DBMS Transaction.

Ans :- Schedule

A series of operation from one transaction to another transaction is known as schedule. It is


used to preserve the order of the operation in each of the individual transaction.

1. Serial Schedule

The serial schedule is a type of schedule where one transaction is executed completely before
starting another transaction. In the serial schedule, when the first transaction completes its
cycle, then the next transaction is executed.
2. Non-serial Schedule

If interleaving of operations is allowed, then there will be non-serial schedule.

It contains many possible orders in which the system can execute the individual operations of
the transactions.

Serializable and Non Serializable schedule

The serializability of schedules is used to find non-serial schedules that allow the transaction
to execute concurrently without interfering with one another. It identifies which schedules
are correct when executions of the transaction have interleaving of their operations.

A non-serial schedule will be serializable if its result is equal to the result of its transactions
executed serially.
Schedule A and Schedule B are serial schedule.

Schedule C and Schedule D are Non-serial schedule.

1. Conflict Serializability

 Conflict serializability defines two instructions of two different transactions accessing


the same data item to perform a read/write operation.

 It deals with detecting the instructions that are conflicting in any way and specifying
the order in which the instructions should execute in case there is any conflict.

 A conflict serializability arises when one of the instructions is a write operation.

2. View Serializability

 View serializability is another type of serializability.

 It can be derived by creating another schedule out of an existing schedule and involves
the same set of transactions
Recoverable Schedule

If in a schedule,

 A transaction performs a dirty read operation from an uncommitted transaction

 And its commit operation is delayed till the uncommitted transaction either commits
or roll backs

then such a schedule is known as a Recoverable Schedule.

Example
Let us consider two transaction schedules as given below −

T1 T2

Read(A)

Write(A)

- Read(A) ///Dirty Read

- Write(A)

Commit

Commit // delayed

The above schedule is a recoverable schedule because of the reasons mentioned below-

 The transaction T2 performs dirty read operation on A.


 The commit operation of transaction T2 is delayed until transaction T1 commits or
rollback.

 Transaction commits later.

 In the above schedule transaction T2 is now allowed to commit whereas T1 is not yet
committed.

 In this case transaction T1 is failed, and transaction T2 still has a chance to recover by
rollback.

Irrecoverable Schedules-

If in a schedule,

 A transaction performs a dirty read operation from an uncommitted transaction

 And commits before the transaction from which it has read the value
then such a schedule is known as an Irrecoverable Schedule.

Q.10 What is Deadlock in DBMS? explain classical approaches for deadlock handling

Ans- Deadlock in DBMS

A deadlock is a condition where two or more transactions are waiting indefinitely for one
another to give up locks. Deadlock is said to be one of the most troubled complications in
DBMS as no task ever gets finished and is in waiting state forever.

For example: In the student table, transaction T1 holds a lock on some rows and needs to update
some rows in the grade table. Simultaneously, transaction T2 holds locks on some rows in the
grade table and needs to update the rows in the Student table held by Transaction T1.

Now, the main problem arises. Now Transaction T1 is waiting for T2 to release its lock and
similarly, transaction T2 is waiting for T1 to release its lock. All activities come to a halt state
and remain at a standstill. It will remain in a standstill until the DBMS detects the deadlock
and aborts one of the transactions.
Deadlock Handling in Centralized Systems

There are three classical approaches for deadlock handling, namely −

 Deadlock prevention.

 Deadlock avoidance.

 Deadlock detection and removal.

Deadlock Prevention

The deadlock prevention approach does not allow any transaction to acquire locks that will
lead to deadlocks. The convention is that when more than one transaction request for locking
the same data item, only one of them is granted the lock.

Deadlock Avoidance

The deadlock avoidance approach handles deadlocks before they occur. It analyses the
transactions and the locks to determine whether or not waiting leads to a deadlock.

Deadlock Detection and Removal

The deadlock detection and removal approach run a deadlock detection algorithm periodically
and removes deadlock in case there is one. It does not check for deadlock when a transaction
places a request for a lock. When a transaction requests a lock, the lock manager checks
whether it is available. If it is available, the transaction is allowed to lock the data item;
otherwise the transaction is allowed to wait.

Q.11 Explain Recovery with Concurrent Transaction in DBMS Transaction.

Ans:- Recovery with Concurrent Transactions


Concurrency control means that multiple transactions can be executed at the same time and
then the interleaved logs occur. But there may be changes in transaction results so maintain the
order of execution of those transactions.

During recovery, it would be very difficult for the recovery system to backtrack all the logs
and then start recovering.

Recovery with concurrent transactions can be done in the following four ways.

 Interaction with concurrency control

 Transaction rollback

 Checkpoints

 Restart recovery

Interaction with concurrency control:

In this scheme, the recovery scheme depends greatly on the concurrency control scheme that
is used. So, to rollback a failed transaction, we must undo the updates performed by the
transaction.

Transaction rollback:

In this scheme, we rollback a failed transaction by using the log.

The system scans the log backward a failed transaction, for every log record found in the log
the system restores the data item.

Checkpoints:

 Checkpoints is a process of saving a snapshot of the applications state so that it can


restart from that point in case of failure.
 Checkpoint is a point of time at which a record is written onto the database form the
buffers.
 Checkpoint shortens the recovery process.
 When it reaches the checkpoint, then the transaction will be updated into the database,
and till that point, the entire log file will be removed from the file. Then the log file is
updated with the new step of transaction till the next checkpoint and so on.
 The checkpoint is used to declare the point before which the DBMS was in the
consistent state, and all the transactions were committed.
 In this scheme, we used checkpoints to reduce the number of log records that the system
must scan when it recovers from a crash.
 In a concurrent transaction processing system, we require that the checkpoint log record
be of the form <checkpoint L>, where ‘L’ is a list of transactions active at the time of
the checkpoint.
 A fuzzy checkpoint is a checkpoint where transactions are allowed to perform updates
even while buffer blocks are being written out.

Restart recovery:

 When the system recovers from a crash, it constructs two lists.


 The undo-list consists of transactions to be undone, and the redo-list consists of
transaction to be redone.
 The system constructs the two lists as follows: Initially, they are both empty. The
system scans the log backward, examining each record, until it finds the first
<checkpoint> record.

Q,.12 Explain SET Operation in DBMS.

Ans: SQL supports few Set operations which can be performed on the table data. These are
used to get meaningful results from data stored in the table, under different special conditions.

In this tutorial, we will cover 4 different types of SET operations, along with example:

1. UNION

2. UNION ALL

3. INTERSECT

4. Minus

UNION Operation

UNION is used to combine the results of two or more SELECT statements. However, it will
eliminate duplicate rows from its result set. In case of union, number of columns and data type
must be same in both the tables, on which UNION operation is being applied.

Example of UNION

The First table The Second table

ID Name

1 abhi
ID Name

2 adam

2 adam 3 Chester

Union SQL query will be: -

SELECT * FROM First UNION SELECT * FROM Second;

The result set table will look like

ID NAME

1 abhi

2 adam

3 Chester

2. UNION ALL
This operation is similar to Union. But it also shows the duplicate rows.

The First table The Second table

ID Name

1 abhi
ID Name

2 adam

2 adam 3 Chester

Union All query will be like

SELECT * FROM First UNION ALL SELECT * FROM Second;

The result set table will look like,

ID NAME

1 abhi

2 adam

2 adam

3 Chester

3. INTERSECT

Intersect operation is used to combine two SELECT statements, but it only retunes the records
which are common from both SELECT statements. In case of Intersect the number of columns
and data type must be same.

NOTE: MySQL does not support INTERSECT operator.

The First table The Second table

ID Name
ID Name

1 abhi 2 adam

2 adam 3 Chester

Intersect query will be:-

SELECT * FROM First INTERSECT SELECT * FROM Second;

The result set table will look like

ID NAME

2 adam

4. Minus

It combines the result of two SELECT statements. Minus operator is used to display the rows
which are present in the first query but absent in the second query.

It has no duplicates and data arranged in ascending order by default.

Syntax:

SELECT column_name FROM table1

MINUS

SELECT column_name FROM table2;

Example: Using the above First and Second table.

SELECT * FROM First

MINUS

SELECT * FROM Second;

The result set table will look like:

ID NAME
1 Jack

2 Harry

Q.13 What are Unary and Binary Relationships explain with example?

Ans:-A relationship in a DBMS, is primarily the way two or more data sets are linked. This is
so true for Relational Database Management Systems. One dataset may be then termed as the
Foreign key and the ones linked to it may be termed as the Primary Key. There may be multiple
Foreign and Primary keys linked to each other.

Relationships allow the datasets to share and store the data in separate tables. They also help
link disparate data with each other.

The most common types of relationships are:

 Unary (one entity is involved in the relationship).

 Binary (two entities are involved in the relationship).

 Ternary (three entities are involved in the relationship)

 N-ary (n entities involved in the relationship)


A unary relationship is when both participants in the relationship are the same entity. For
Example: Subjects may be prerequisites for other subjects. A ternary relationship is when three
entities participate in the relationship.

Example of unary relationship

For example, a person has only one passport and only one passport is given to only one person
and hence unary relationship is observed

A Binary Relationship is the relationship between two different Entities i.e. it is a relationship
of role group of one entity with the role group of another entity.

Example of binary relationship

For example, a teacher teaches a subject here 2 entities are teacher and subject for the
relationship teacher teaches subject

Ternary Relationship: a ternary relationship is a relationship of degree three. That is, a


relationship that contains three participating entities. The cardinality constraint of an entity in
a ternary relationship is defined by a pair of two entity instances associated with the other single
entity instance.

Example of Ternary Relationship


In the real world, a patient goes to a doctor and doctor prescribes the medicine to the patient,
three entities Doctor, patient and medicine are involved in the relationship “prescribes”.

Aggregation in DBMS

Aggregation refers to the process by which entities are combined to form a single meaningful
entity. The specific entities are combined because they do not make sense on their own. To
establish a single entity, aggregation creates a relationship that combines these entities. The
resulting entity makes sense because it enables the system to function well.

When using data in the form of numerical values, the following operations can be used to
perform DBMS aggregation:

Average (AVG): This function provides the mean or average of the data values.

Sum: This provides a total value after the data values have been added.

Count: This provides the number of records.

Maximum (Max): This function provides the maximum value of a given set of data.

Minimum (Min): This provides the minimum value of a given set of data.

Q. 14 Explain Aggregate function with example.

Ans; - SQL Aggregate Functions

SQL aggregation function is used to perform the calculations on multiple rows of a single
column of a table. It returns a single value.
It is also used to summarize the data.

1. COUNT FUNCTION

COUNT function is used to Count the number of rows in a database table. It can work on both
numeric and non-numeric data types.

COUNT function uses the COUNT(*) that returns the count of all the rows in a specified table.
COUNT(*) considers duplicate and Null.

PRODUCT_MAST Table: -

PRODUCT COMPANY QTY RATE COST

Item1 Com1 2 10 20

Item2 Com2 3 25 75

Item3 Com1 2 30 60

Item4 Com3 5 10 50

Item5 Com2 2 20 40

SELECT COUNT (*) FROM PRODUCT_MAST;

Output: - 05

2. SUM Function: - Suppose we want a report that gives total amount of payments made so
far. We can use the SQL SUM function which returns the sum of all the values in the specified
column. SUM works on numeric fields only. Null values are excluded from the result returned.

SELECT SUM(COST) FROM PRODUCT_MAST;

Output: - 245

3.AVG function: -SQL AVG function returns the average of the values in a specified column.
Just like the SUM function, it works only on numeric data types. AVG function returns the
average of all non-Null values.

SELECT AVG(COST) FROM PRODUCT_MAST;

Output: - 49.00

4.MAX Function: - Just as the name suggests, the MAX function is the opposite of the MIN
function. It returns the largest value from the specified table field. Let's assume we want to get
the year that the latest movie in our database was released. We can easily use the MAX function
to achieve that.
SELECT MAX(RATE) FROM PRODUCT_MAST;

Output: - 30

5.MIN Function: - The MIN function returns the smallest value in the specified table field. As
an example, let's suppose we want to know the year in which the oldest movie in our library
was released, we can use SQL's MIN function to get the desired information.

SELECT MIN(RATE) FROM PRODUCT_MAST;

Q.15 Explain the BCNF and Third Normal Form with example.

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


same table that causes a functional dependency. To achieve the normalization standard of
Third Normal Form (3NF), you must eliminate any transitive dependency.

{Book} ->{Author} (if we know the book, we know the author name)

{Author} -> {Author_age} Therefore, as per the rule of transitive dependency:

{Book} -> {Author_age} should hold,

Book Author Author_age

Game of Thrones George R. R. Martin 66

Harry Potter J. K. Rowling 49

Dying of the Light George R. R. Martin 66

Third Normal Form

A relation will be in 3NF if it is in 2NF and not contain any transitive partial dependency.

3NF is used to reduce the data duplication. It is also used to achieve the data integrity.

If there is no transitive dependency for non-prime attributes, then the relation must be in
third normal form.

A relation is in third normal form if it holds at least one of the following conditions for every
non-trivial function dependency X → Y.

X is a super key.

Y is a prime attribute, i.e., each element of Y is part of some candidate key.

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.

Candidate Key: The minimal set of attributes 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.

Example of Super & Candidate Key

Example: - EMPLOYEE_DETAIL

EMP_ID EMP_NAME EMP_ZIP EMP_STATE EMP_CITY


222 Harry 201010 UP Noida

333 Stephan 02228 US Boston

444 Lan 60007 US Chicago

555 Katharine 06389 UK Norwich

666 John 462007 MP Bhopal

Super key in the table above:

{EMP_ID}, {EMP_ID, EMP_NAME}, {EMP_ID, EMP_NAME, EMP_ZIP} ....so on.

Candidate key: {EMP_ID}

Non-prime attributes: In the given table, all attributes except EMP_ID are non-prime.

Here, EMP_STATE & EMP_CITY dependent on EMP_ZIP and EMP_ZIP dependent on


EMP_ID.

The non-prime attributes (EMP_STATE, EMP_CITY) transitively dependent on super key


(EMP_ID). It violates the rule of third normal form.

That's why we need to move the EMP_CITY and EMP_STATE to the new <EMPLOYEE_ZIP>
table, with EMP_ZIP as a Primary key.

EMPLOYEE Table: -

EMP_ID EMP_NAME EMP_ZIP

222 Harry 201010


333 Stephan 02228

444 Lan 60007

555 Katharine 06389

666 John 462007

Super key in the table above:

{EMP_ID}, {EMP_ID, EMP_NAME}, {EMP_ID, EMP_NAME, EMP_ZIP} ....so on .

Candidate key: {EMP_ID}

Non-prime attributes: In the given table, all attributes except EMP_ID are non-prime.

Here, EMP_STATE & EMP_CITY dependent on EMP_ZIP and EMP_ZIP dependent on


EMP_ID.The non-prime attributes (EMP_STATE, EMP_CITY) transitively dependent on
super key (EMP_ID). It violates the rule of third normal form.

That's why we need to move the EMP_CITY and EMP_STATE to the new <EMPLOYEE_ZIP>
table, with EMP_ZIP as a Primary key.

EMPLOYEE Table: -

EMP_ID EMP_NAME EMP_ZIP

222 Harry 201010

333 Stephan 02228

444 Lan 60007


555 Katharine 06389

666 John 462007

EMPLOYEE_ZIP Table:

EMP_ZIP EMP_STATE EMP_CITY

201010 UP Noida

02228 US Boston

60007 US Chicago

06389 UK Norwich

462007 MP Bhopal

It is an advance version of 3NF that’s it is also referred as 3.5NF.

A table complies with BCNF if it is in 3NF and for every functional dependency X->Y, X
should be the super key of the table.

Functional Dependency

Functional Dependency (FD) determines the relation of one attribute to another attribute
in a database management system (DBMS) system.

Functional dependency helps you to maintain the quality of data in the database.
A functional dependency is denoted by an arrow →. The functional dependency of X on Y
is represented by X → Y.

Example: Suppose there is a company wherein employees work in more than one
department. They store the data like this:

emp_i emp_nationalit emp_dept dept_typ dept_no_of_em


d y e p

1001 Austrian Production D001 200


and
planning

1001 Austrian stores D001 250

1002 American design and D134 100


technical
support

1002 American Purchasing D134 600


departmen
t

Functional dependencies in the table above:


emp_id -> emp_nationality

emp_dept -> {dept_type, dept_no_of_emp}.

Candidate key: {emp_id, emp_dept}

The table is not in BCNF as neither emp_id nor emp_dept alone are keys.

To make the table comply with BCNF we can break the table in three tables like this:

emp_nationality:

emp_id emp_nationality

1001 Austrian

1002 American
emp_dept table:

emp_dept dept_type dept_no_of_emp

Production and planning D001 200

Stores D001 250

design and technical support D134 100

Purchasing department D134 600

emp_dept_mapping table:

emp_id emp_dept

1001 Production and planning

1001 Stores

1002 design and technical support

1002 Purchasing department

Functional dependencies:
emp_id -> emp_nationality

emp_dept -> {dept_type, dept_no_of_emp}

Candidate keys:
For first table: emp_id

For second table: emp_dept

For third table: {emp_id, emp_dept}

This is now in BCNF as in both the functional dependencies left side part is a key.

You might also like