Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

1)•Define growing and shrinking phase of two phase locking protocol with proper example.

Growing phase:
All the locks are issued in this phase. No locks are released, after all changes to data-items are
committed and then the second phase (shrinking phase) starts.
Shrinking phase:
No locks are issued in this phase, all the changes to data-items are noted (stored) and then
locks are released.

Example:
Transaction T1:

o Growing phase: from step 1-3


o Shrinking phase: from step 5-7
o Lock point: at 3

Transaction T2:
o Growing phase: from step 2-6
o Shrinking phase: from step 8-9
o Lock point: at 6

••Explain Dirty Read problem with example.


Dirty read is a read of uncommitted data. If a particular row is modified by another running
application and not yet committed, we also run an application to read the same row with the
same uncommitted data. This is the state we say it as a dirty read.

Example:
Consider two people A and B are trying to book a train ticket from the IRCTC platform. Let’s
suppose they perform the following sequence of events –
Now let’s say initially (before A and B started the booking process) 4 seats were available. Then,
A came and read SEATS as 4, then he started the booking process, and hence he decreased the

value of SEATS to 3. Now, B came and read the count of seats i.e. SEATS to be 3. But after some
time the transaction of A got ROLLBACKED (say due to an issue with the payment gateway).
Then the value of SEATS will get updated to its initial value i.e. 4. And thus, we can say B has
read a Dirty value of SEATS.

2)•What is view? Explain with example.


Views in SQL are kind of virtual tables. A view also has rows and columns as they are in a real
table in the database. We can create a view by selecting fields from one or more tables present
in the database. A View can either have all the rows of a table or specific rows based on certain
condition.
Example:

Following is an example to create a view from the CUSTOMERS table. This view would be used
to have customer name and age from the CUSTOMERS table.
SQL > CREATE VIEW CUSTOMERS_VIEW AS

SELECT name, age


FROM CUSTOMERS;
Now, you can query CUSTOMERS_VIEW in a similar way as you query an actual table. Following
is an example for the same.
SQL > SELECT * FROM CUSTOMERS_VIEW;

This would produce the following result.


••Deletion of a view in database.
We can delete or drop a View using the DROP statement. Syntax:
DROP VIEW view_name;

View_name: Name of the View which we want to delete.


For example, if we want to delete the View MarksView, we can do this as:
DROP VIEW MarksView;
3)Explain ACID properties in transaction.

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.

o Atomicity- The term atomicity defines that the data remains atomic. It means if any
operation is performed on the data, either it should be performed or executed
completely or should not be executed at all.
o Consistency- The word consistency means that the value should remain preserved
always.In DBMS, the integrity of the data should be maintained, which means if a

change in the database is made, it should remain preserved always.


o Isolation- The term ‘isolation’ means separation. In DBMS, Isolation is the property of a
database where no data should affect the other one and may occur concurrently.
o Durability- Durability ensures the permanency of something. 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.
4)What are the semantic constraints in SQL? Explain with example.
5)•Describe various indexes based on ordering of the key field.
Ordered Indexing is of two types –
i. Dense Index- In dense index, there is an index record for every search key value in the
database. This makes searching faster but requires more space to store index records
itself. Index records contain search key value and a pointer to the actual record on the

disk.
ii. Sparse Index- In sparse index, index records are not created for every search key. An
index record here contains a search key and an actual pointer to the data on the disk. To
search a record, we first proceed by index record and reach at the actual location of the
data. If the data we are looking for is not where we directly reach by following the
index, then the system starts sequential search until the desired data is found.
••Explain the roles and responsibilities of DBA.
A database administrator (DBA) is a person or group in charge of implementing DBMS in an
organization. The DBA job requires a high degree of technical expertise. DBA consists of a team
of people rather than just one person.

Roles:
The primary role of Database administrator is as follows –
i. Database design
ii. Performance issues
iii. Database accessibility
iv. Capacity issues
v. Data replication
vi. Table Maintenance

Responsibility:
i. Responsible for designing overall database schema (tables & fields).
ii. To select and install database software and hardware.
iii. Responsible for deciding on access methods and data storage.
iv. DBA selects appropriate DBMS software like oracle, SQL server or MySQL.
v. Used in designing recovery procedures.
vi. DBA decides the user access level and security checks for accessing, modifying or
manipulating data.
vii. DBA is responsible for specifying various techniques for monitoring the database
performance.
viii. DBA is responsible for operation managements.
ix. The operation management deals with the data problems which arises on day to day
basis, and the responsibilities include are:
a) Investigating if any error is been found in the data.
b) Supervising of restart and recovery procedures in case of any event failure.
c) Supervising reorganization of the databases.
d) Controlling and handling all periodic dumps of data.
6)Draw ER Diagram for Library Management System.

7)How foreign key maintains referential integrity in a database. Explain with example.

8)What is Redundancy? Explain the anomalies in relational database.


Redundancy:

Redundancy in DBMS is the problem that arises when the database is not normalized. It is the
concept of storing multiple copies of the same data in different parts of the database.
Example for Redundancy in DBMS:

In this student table, we have repeated the same department details, dept_id, dept_name, and
dept_head in every student record. This causes redundancy in the student table.
Anamolies in relational database:
These anomalies can be categorized into three types:

i. Insertion Anomalies: These anomalies occur when it is not possible to insert data into a
database because the required fields are missing or because the data is incomplete. For
example, if a database requires that every record has a primary key, but no value is
provided for a particular record, it cannot be inserted into the database.
ii. Deletion anomalies: These anomalies occur when deleting a record from a database
and can result in the unintentional loss of data. For example, if a database contains
information about customers and orders, deleting a customer record may also delete all
the orders associated with that customer.
iii. Update anomalies: These anomalies occur when modifying data in a database and can
result in inconsistencies or errors. For example, if a database contains information about
employees and their salaries, updating an employee’s salary in one record but not in all
related records could lead to incorrect calculations and reporting.
9)Explain unary operators with example.
All those Operators which operate on a single operand are known as unary operators.
Unary operators are of three types-
i. Selection Operator:
• Selection Operator (σ) performs a selection operation.
• It selects those rows or tuples from the table which satisfies the selection condition.
• It works with rows(tuples)
ii. Projection Operator:
• Projection Operator (π) displays the columns of a table based on the specified
attributes.
• It just works on Columns
iii. Rename Operation (ρ):
• To rename relation the rename operation is used which allows us to rename the output
relation
• .’Rename’ operation is denoted with rho(ρ).

10)••Give examples for partial dependency and non-transitive dependency.


12)••Explain View Serializability with example.
View serializability is a concept that is used to compute whether schedules are View-
Serializable or not. A schedule is said to be View-Serializable if it is view equivalent to a Serial
Schedule (where no interleaving of transactions is possible).
Example:
As we know that in Serial schedule a transaction only starts when the current running

transaction is finished. So the serial schedule of the above given schedule would look like this:

If we can prove that the given schedule is View Equivalent to its serial schedule then the given
schedule is called view Serializable.
•••Immediate database modification and deferred database modification in database.
Immediate database modification:
o The Immediate modification technique occurs if database modification occurs while the
transaction is still active.
o In this technique, the database is modified immediately after every operation. It follows
an actual database modification.
Deferred database modification:

o The deferred modification technique occurs if the transaction does not modify the
database until it has committed.
o In this method, all the logs are created and stored in the stable storage, and the
database is updated when a transaction commits.

13)•••Explain the use of group by and having clause:


Group by Clause:
The GROUP BY clause is often used with aggregate functions (MAX, SUM, AVG) to group the
results by one or more columns or In simple words we can say that The GROUP BY clause is
used in collaboration with the SELECT statement to arrange required data into groups.

The GROUP BY statement groups rows that have the same values. This Statement is used after
the where clause. This statement is often used with some aggregate function like SUM, AVG,
COUNT atc. To group the results by one or more columns.
Having Clause :

Having Clause is basically like the aggregate function with the GROUP BY clause. The HAVING
clause is used instead of WHERE with aggregate functions. While the GROUP BY Clause groups
rows that have the same values into summary rows. The having clause is used with the where
clause in order to find rows with certain conditions. The having clause is always used after the
group By clause.
15)••Explain the process of Check-point based recovery with suitable example.
Checkpoints play a crucial role in the recovery process of a DBMS. In the event of a system
failure or crash, the DBMS uses the information stored in the checkpoint and transaction log to
recover the database to its last known state. The recovery process begins by reading the
transaction log and replaying any committed transactions that occurred after the last
checkpoint. This process is known as “roll forward.” The DBMS then applies any changes that
were made to the database but not yet committed, also known as “rollback.”

• The recovery system reads log files from the end to start. It reads log files from T4 to T1.
• Recovery system maintains two lists, a redo-list, and an undo-list.
• The transaction is put into redo state if the recovery system sees a log with <Tn, Start>
and <Tn, Commit> or just <Tn, Commit>. In the redo-list and their previous list, all the
transactions are removed and then redone before saving their logs.
For example: In the log file, transaction T2 and T3 will have <Tn, Start> and <Tn, Commit>. The

T1 transaction will have only <Tn, commit> in the log file. That’s why the transaction is
committed after the checkpoint is crossed. Hence it puts T1, T2 and T3 transaction into redo
list.
The transaction is put into undo state if the recovery system sees a log with <Tn, Start> but no
commit or abort log found. In the undo-list, all the transactions are undone, and their logs are
removed.
For example: Transaction T4 will have <Tn, Start>. So T4 will be put into undo list since this
transaction is not yet complete and failed amid.
•••With proper example explain how recovery in a database system can be done using LOG
files when the following techniques are used- Immediate update technique Deferred update
technique.
16)•Explain ACID property and its importance
Importance:

1) Data Consistency: ACID properties ensure that the data remains consistent and accurate
after any transaction execution.
2) Data Integrity: ACID properties maintain the integrity of the data by ensuring that any
changes to the database are permanent and cannot be lost.
3) Concurrency Control: ACID properties help to manage multiple transactions occurring
concurrently by preventing interference between them.
4) Recovery: ACID properties ensure that in case of any failure or crash, the system can
recover the data up to the point of failure or crash.
••Explain Wait-Die & Wound Wait protocols.

Wait-Die Scheme:
In this scheme, If a transaction requests a resource that is locked by another transaction, then
the DBMS simply checks the timestamp of both transactions and allows the older transaction to
wait until the resource is available for execution.

Wound Wait Scheme:


In this scheme, if an older transaction requests for a resource held by a younger transaction,
then an older transaction forces a younger transaction to kill the transaction and release the
resource. The younger transaction is restarted with a minute delay but with the same
timestamp. If the younger transaction is requesting a resource that is held by an older one, then
the younger transaction is asked to wait till the older one releases it.
Short note
14)1)3 schema architecture:

• The three schema architecture is also called ANSI/SPARC architecture or three-level


architecture.
• This framework is used to describe the structure of a specific database system.
• The three schema architecture is also used to separate the user applications and
physical database.
• The three schema architecture contains three-levels. It breaks the database down into
three different categories.
This architecture contains three layers of database management system, which are as follows –

a) Internal Level-
• The internal level has an internal schema which describes the physical storage
structure of the database.
• The internal schema is also known as a physical schema.
• It uses the physical data model. It is used to define that how the data will be stored
in a block.
• The physical level is used to describe complex low-level data structures in detail.

b) Conceptual Level:
• The conceptual schema describes the design of a database at the conceptual level.
Conceptual level is also known as logical level.
• The conceptual schema describes the structure of the whole database.
• The conceptual level describes what data are to be stored in the database and also
describes what relationship exists among those data.
• In the conceptual level, internal details such as an implementation of the data
structure are hidden.
• Programmers and database administrators work at this level.
c) External Level:
• At the external level, a database contains several schemas that sometimes called as
subschema. The subschema is used to describe the different view of the database.
• An external schema is also known as view schema.
• Each view schema describes the database part that a particular user group is
interested and hides the remaining database from that user group.
• The view schema describes the end user interaction with database systems.

2)Extended E-R features:


Extended ER is a high-level data model that incorporates the extensions to the original ER
model. Enhanced ER models are high level models that represent the requirements and
complexities of complex databases.
The extended Entity Relationship (ER) models are three types as given below −
a) Specialization- The process of designing sub groupings within an entity set is called
specialization. It is a top-down process. If an entity set is given with all the attributes
in which the instances of the entity set are differentiated according to the given
attribute value, then that sub-classes or the sub-entity sets can be formed from the
given attribute.
b) Generalization- It is the reverse process of specialization. It is a bottom-up
approach.
It converts subclasses to superclasses. This process combines a number of entity sets
that share the same features into higher-level entity sets.
c) Aggregation- It is an abstraction in which relationship sets are treated as higher level
entity sets and can participate in relationships. Aggregation allows us to indicate
that a relationship set participates in another relationship set.
Aggregation is used to simplify the details of a given database where ternary
relationships will be changed into binary relationships. Ternary relation is only one
type of relationship which is working between three entities.
3)Conflict serializable schedule:

• A schedule is called conflict serializability if after swapping of non-conflicting operations,


it can transform into a serial schedule.
• The schedule will be a conflict serializable if it is conflict equivalent to a serial schedule.

Conflicting Operations:
The two operations become conflicting if all conditions satisfy:
I. Both belong to separate transactions.
II. They have the same data item.
III. They contain at least one write operation.
4)SQL Subqueries:
A Subquery or Inner query or a Nested query is a query within another SQL query and
embedded within clauses, most commonly in the WHERE clause. It is used to return data from a
table, and this data will be used in the main query as a condition to further restrict the data to
be retrieved.
Important rules for Subqueries:

• You can place the Subquery in a number of SQL clauses: WHERE clause, HAVING clause,
FROM clause. Subqueries can be used with SELECT, UPDATE, INSERT, DELETE statements
along with expression operator. It could be equality operator or comparison operator
such as =, >, =, <= and Like operator.
• A subquery is a query within another query. The outer query is called as main query and
inner query is called as subquery.
• The subquery generally executes first when the subquery doesn’t have any co-relation
with the main query, when there is a co-relation the parser takes the decision on the fly
on which query to execute on precedence and uses the output of the subquery
accordingly.
• Subquery must be enclosed in parentheses.
• Subqueries are on the right side of the comparison operator.
• ORDER BY command cannot be used in a Subquery. GROUPBY command can be used to
perform same function as ORDER BY command.
• Use single-row operators with singlerow Subqueries. Use multiple-row operators with
multiple-row Subqueries.
5)Database recovery and shadow paging:
Database recovery:
Database recovery techniques are used in database management systems (DBMS) to restore a
database to a consistent state after a failure or error has occurred. The main goal of recovery
techniques is to ensure data integrity and consistency and prevent data loss. There are mainly
two types of recovery techniques used in DBMS:
Rollback/Undo Recovery Technique: The rollback/undo recovery technique is based on the
principle of backing out or undoing the effects of a transaction that has not completed
successfully due to a system failure or error. This technique is accomplished by undoing the
changes made by the transaction using the log records stored in the transaction log. The
transaction log contains a record of all the transactions that have been performed on the
database. The system uses the log records to undo the changes made by the failed transaction
and restore the database to its previous state.
Commit/Redo Recovery Technique: The commit/redo recovery technique is based on the
principle of reapplying the changes made by a transaction that has been completed successfully
to the database. This technique is accomplished by using the log records stored in the
transaction log to redo the changes made by the transaction that was in progress at the time of
the failure or error. The system uses the log records to reapply the changes made by the
transaction and restore the database to its most recent consistent state.
Shadow paging:

Shadow paging is one of the techniques that is used to recover from failure. We all know that
recovery means to get back the information, which is lost. It helps to maintain database
consistency in case of failure.
Advantages:

I. No need for log records.


II. No undo/ Redo algorithm.
III. Recovery is faster.
Disadvantages:
I. Data is fragmented or scattered.
II. Garbage collection problem. Database pages containing old versions of modified data
need to be garbage collected after every transaction.
III. Concurrent transactions are difficult to execute.
6)Lossless join decomposition:

Lossless-join decomposition is a process in which a relation is decomposed into two or more


relations. This property guarantees that the extra or less tuple generation problem does not
occur and no information is lost from the original relation during the decomposition. It is also
known as non-additive join decomposition.

Consider a relation R if we decomposed it into sub-parts relation R1 and relation R2.


The decomposition is lossless when it satisfies the following statement –

• If we union the sub Relation R1 and R2 then it must contain all the attributes that are
available in the original relation R before decomposition.
• Intersections of R1 and R2 cannot be Null. The sub relation must contain a common
attribute. The common attribute must contain unique data.
7)SQL Check Constraints:
The CHECK Constraint enables a condition to check the value being entered into a record. If the
condition evaluates to false, the record violates the constraint and isn’t entered the table.
• The predicate in check constraint can hold a sub query.
• Check constraint defined on an attribute restricts the range of values for that attribute.
• If the value being added to an attribute of a tuple violates the check constraint, the
check constraint evaluates to false and the corresponding update is aborted.
• Check constraint is generally specified with the CREATE TABLE command in SQL.
8) B+ tree index:

• The B+ tree is a balanced binary search tree. It follows a multi-level index format.
• In the B+ tree, leaf nodes denote actual data pointers. B+ tree ensures that all leaf
nodes remain at the same height.
• In the B+ tree, the leaf nodes are linked using a link list. Therefore, a B+ tree can support
random access as well as sequential access.

Features of B+ Trees:
I. Balanced: B+ Trees are self-balancing, which means that as data is added or removed
from the tree, it automatically adjusts itself to maintain a balanced structure. This
ensures that the search time remains relatively constant, regardless of the size of the
tree.
II. Multi-level: B+ Trees are multi-level data structures, with a root node at the top and
one or more levels of internal nodes below it. The leaf nodes at the bottom level contain
the actual data.
III. Ordered: B+ Trees maintain the order of the keys in the tree, which makes it easy to
perform range queries and other operations that require sorted data.
IV. Fan-out: B+ Trees have a high fan-out, which means that each node can have many child
nodes. This reduces the height of the tree and increases the efficiency of searching and
indexing operations.
V. Cache-friendly: B+ Trees are designed to be cache-friendly, which means that they can
take advantage of the caching mechanisms in modern computer architectures to
improve performance.
VI. Disk-oriented: B+ Trees are often used for disk-based storage systems because they are
efficient at storing and retrieving data from disk.

9)Relational calculus:

There is an alternate way of formulating queries known as Relational Calculus. Relational


calculus is a non-procedural query language. In the non-procedural query language, the user is
concerned with the details of how to obtain the end results. The relational calculus tells what to
do but never explains how to do. Most commercial relational languages are based on aspects of
relational calculus including SQL-QBE and QUEL.
Relational Calculus is of Two Types:

I. Tuple Relational Calculus (TRC)


II. Domain Relational Calculus (DRC)
10)2 phase locking protocol:

• The two-phase locking protocol divides the execution phase of the transaction into
three parts.
• In the first part, when the execution of the transaction starts, it seeks permission for the
lock it requires.
• In the second part, the transaction acquires all the locks. The third phase is started as
soon as the transaction releases its first lock.
• In the third phase, the transaction cannot demand any new locks. It only releases the
acquired locks.
There are two phases of 2PL:

I. Growing phase: In the growing phase, a new lock on the data item may be acquired by
the transaction, but none can be released.
II. Shrinking phase: In the shrinking phase, existing lock held by the transaction may be
released, but no new locks can be acquired.

Two phase locking is of two types –


I. Strict two phase locking protocol
II. Rigorous two phase locking protocol

You might also like