Professional Documents
Culture Documents
DBMS 1st Suggestion
DBMS 1st Suggestion
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:
Transaction T2:
o Growing phase: from step 2-6
o Shrinking phase: from step 8-9
o Lock point: at 6
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.
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
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
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.
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(ρ).
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.
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.
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.
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:
• 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:
• 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.