DBMS Madam Impt List
DBMS Madam Impt List
2marks
• A database system (DBMS) manages data using tables, supports querying, provides
security, and reduces redundancy.
• Data independence refers to the ability to change the schema at one level without affecting
the other levels.
• Types:
• A relationship set is a collection of relationships of the same type between entity sets.
Example: Enrolled relates Student and Course.
2. End Users – Use applications to retrieve or update data (like checking results or booking
tickets).
fi
fi
fi
fi
fi
fi
fi
7. What is the purpose of the three-tier schema architecture in DBMS?
• It separates the user view, logical structure, and physical storage, allowing data
independence and easier management.
LONG ANSWERS
1. Compare the Characteristics of the File System and Database System with Proper
Examples (10 Marks)
File System: A le system stores data in les that are scattered across the disk and managed by the
operating system. Each le may represent a different type of data, and relationships are not
enforced.
Database System (DBMS): A DBMS stores data in a structured way using tables with
relationships. It provides tools for data management, querying, and integrity enforcement.
A database system is composed of several components that work together to manage data
effectively.
Components:
1. Hardware: Physical devices like servers, storage systems, and client terminals.
fi
fi
fi
fi
fi
fi
fi
fi
2. Software: Includes the DBMS software (e.g., Oracle, MySQL), OS, and application
interfaces.
3. Data: The actual data stored, along with metadata and system logs.
4. Users: People interacting with the system (DBA, developers, end users).
DBMS Subcomponents:
• Query Processor: Interprets SQL queries and converts them into low-level instructions.
Diagram:
3. Different Types of Users in a Database Environment and Their Roles (10 Marks)
2. Database Designers:
◦ De ne the logical and physical structure of the database
3. Application Programmers:
◦ Write applications that interact with the database
4. End Users:
◦ Use applications to query and manipulate data
5. System Analysts:
◦ Bridge the gap between end-users and developers
fi
◦ Analyze requirements and help design solutions
4. Explain the Three-Tier Schema Architecture and Its Signi cance (10 Marks)
Diagram:
1. Hierarchical Model:
◦ Organizes data in a tree structure
◦ Parent-child relationship
2. Network Model:
◦ Records connected through links
5. Object-Oriented Model:
◦ Integrates object-oriented programming with databases
Entities:
Relationship:
• Registers (DateOfRegistration)
ER Diagram:
Example:
ER Representation:
Person
/ \
Student Teacher
Advantages:
Real-World Applications:
2marks
1. What is a relation in the relational model? Give an example.
A relation is a table with rows and columns used to represent data in the relational model.
Example: A STUDENT table with columns: ID, Name, and Age.
3. What are null values in a relational database? Why are they important?
Null values represent missing or unknown data.
They help handle optional data and maintain data integrity.
• Primary Key: A selected candidate key used to uniquely identify tuples in a table.
7. Write the SQL command to create a table named STUDENT with attributes ID, Name, and
Age.
sql
CopyEdit
CREATE TABLE STUDENT (
ID INT,
Name VARCHAR(50),
Age INT
);
fi
fi
8. Write an SQL command to insert a new record into a table named EMPLOYEE.
sql
CopyEdit
INSERT INTO EMPLOYEE (ID, Name, Salary)
VALUES (101, 'John Doe', 50000);
Long answers
1. Explain the basic concepts of the relational model, including domain, attribute, tuple, and
relation. Provide examples.
The relational model is a way of structuring data in tables (relations), where each table is made up
of rows (tuples) and columns (attributes). It is a foundation for relational database management
systems (RDBMS).
• Domain: A domain refers to the set of permissible values for a given attribute. For example,
for the "Age" attribute, the domain might be integers between 0 and 150.
• Relation: A relation is a table consisting of tuples, where each tuple is a record and each
attribute is a column.
◦ Example: A Student table with attributes ID, Name, and Age would be a
relation.
I Ag
Name
D e
1 Alice 22
2 Bob 23
Charli
3 21
e
2. Discuss various types of constraints in the relational model: Domain, Key, and Integrity
constraints. Why are they important?
• Domain Constraints: Ensure that the values in an attribute belong to the speci ed domain.
It restricts the data type or range of values allowed for an attribute.
fi
◦ Example: The Age attribute can only have values between 0 and 150 (domain
constraint).
• Key Constraints: Ensure that each tuple in a relation is uniquely identi able. The primary
key is one or more attributes that uniquely identify a tuple in a relation.
◦ Example: The ID attribute in the Student table can be a primary key because it
uniquely identi es each student.
▪ Referential Integrity: Ensures that foreign keys in one table must match
primary keys in another table.
Importance:
• Data Consistency: Constraints help maintain data accuracy and prevent errors.
• Data Integrity: They ensure that the relationships between tables are logical and correct.
• Reliability: Constraints make sure that data adheres to speci c rules, which reduces the
possibility of invalid or corrupted data.
• Role of Null Values: A null value in a relational database represents missing, unknown, or
inapplicable data. It is used when the actual value is not available.
Example: If a Student table has a DateOfGraduation column, a student who
hasn't graduated yet might have a NULL value in this column.
• Impact:
◦ Data Integrity: Null values allow exibility in representing missing data but may
lead to inconsistencies if not handled properly.
◦ Database Design: The presence of null values can complicate data processing, such
as when aggregating data, performing joins, or calculating averages.
4. Differentiate between relational algebra and relational calculus. Also, discuss their
signi cance in querying databases.
fi
fi
fl
fi
fi
• Relational Algebra: A procedural query language that provides a set of operations (like
SELECT, PROJECT, JOIN) to manipulate relations and retrieve the required data. It de nes
how the result is to be computed.
• Relational Calculus: A non-procedural query language where you specify what data to
retrieve without describing how to get it. It uses mathematical logic to express queries.
Signi cance:
• Relational Algebra: It is closer to how a database engine works and is more ef cient for
optimization. It focuses on step-by-step query execution.
• Relational Calculus: It is more declarative and allows users to express complex queries
without worrying about execution strategy, making it useful for abstract querying.
5. Write SQL statements to create a table, insert records, update a record, and delete a record.
Use a simple database schema like STUDENT or EMPLOYEE.
1. Create a Table:
sql
CopyEdit
7. Insert Records:
sql
CopyEdit
11.
13.
6. De ne relational algebra. Explain at least four basic operations (Select, Project, Union,
Cartesian Product) with examples.
• Relational Algebra: A formal query language that consists of a set of operations used to
retrieve and manipulate data from relational databases.
◦ Explanation: Selects all students where the age is greater than 21.
◦ Example: π(Name)(Student)
4. Cartesian Product (×): Combines two relations into a new relation with every combination
of rows.
• Relational Calculus: A declarative query language that speci es what to retrieve without
de ning how to retrieve it. It uses logical expressions to de ne queries.
• Domain Relational Calculus (DRC): Speci es the query as a set of values from the
domain of the attributes.
Difference:
• TRC refers to entire tuples (rows), while DRC refers to individual attribute values.
8. Design a simple relational database schema for a library system. Include table de nitions,
constraints, and sample SQL commands for data manipulation.
Tables:
1. Insert Book:
sql
CopyEdit
2.
3. Insert Member:
sql
CopyEdit
INSERT INTO Member (MemberID, Name, JoinDate) VALUES
(101, 'John Doe', '2023-04-15');
4.
5. Insert Loan:
sql
CopyEdit
• WHERE Clause: The WHERE clause is used to lter records before any grouping occurs. It
is used to lter rows based on a condition.
• HAVING Clause: The HAVING clause is used to lter records after grouping has been
applied (i.e., it is used with aggregate functions like COUNT, SUM, AVG).
3. Name any two SQL Date and Time functions with their use.
A subquery is a query nested inside another query, usually in the WHERE, FROM, or SELECT
clause. It allows for more complex ltering or computation within the main query.
Example:
sql
CopyEdit
SELECT Name FROM Employee
WHERE Salary > (SELECT AVG(Salary) FROM Employee);
This query nds employees whose salary is greater than the average salary in the Employee
table.
fi
fi
fi
fi
fi
fi
fi
5. List any two aggregate functions in SQL and explain brie y.
1. COUNT(): Returns the number of rows that match the speci ed condition.
◦ Example: SELECT COUNT(*) FROM Employee WHERE
Department = 'HR';
◦ Explanation: Returns the count of employees in the HR department.
The GROUP BY clause is used to arrange identical data into groups based on one or more
columns. It is commonly used with aggregate functions like COUNT(), SUM(), AVG(), etc., to
perform calculations on each group of records.
Example:
sql
CopyEdit
SELECT Department, AVG(Salary) FROM Employee
GROUP BY Department;
This query groups employees by department and calculates the average salary for each department.
• Updatable View: An updatable view allows data modi cations (such as INSERT,
UPDATE, or DELETE) on the view, which are re ected in the underlying base table. The
view must directly reference a single table and have no complex calculations or joins.
• Non-updatable View: A non-updatable view does not allow modi cations because it may
involve multiple tables, joins, or complex calculations that make it impossible to map the
changes back to the underlying tables.
◦ Example: A view combining data from multiple tables with joins and aggregates.
8. Write the syntax of an INNER JOIN and brie y explain its purpose.
Syntax:
sql
CopyEdit
fi
fl
fl
fi
fi
fl
fi
SELECT columns
FROM table1
INNER JOIN table2
ON table1.column = table2.column;
Purpose: The INNER JOIN is used to retrieve records that have matching values in both tables.
It only returns rows where there is a match in both tables based on the condition speci ed in the ON
clause.
Example:
sql
CopyEdit
SELECT Employee.Name, Department.Name
FROM Employee
INNER JOIN Department
ON Employee.DepartmentID = Department.ID;
This query returns the names of employees and the names of their departments, only where there is
a match between the Employee and Department tables.
Long Answers
1. Write SQL queries to demonstrate the use of SELECT and PROJECT
operations along with arithmetic and logical conditions. Include the WHERE
clause.
• SELECT Operation: This operation retrieves data from one or more columns.
Example:
sql
CopyEdit
-- SELECT operation: Retrieves all columns from the Employee
table where salary is greater than 50000
SELECT * FROM Employee
WHERE Salary > 50000;
Date/Time Functions:
SELECT NOW();
2.
4.
Numeric Functions:
2.
3. CEIL(): Returns the smallest integer greater than or equal to the numeric value.
sql
CopyEdit
fi
fi
SELECT CEIL(123.45); -- Output: 124
4.
2.
4.
Example:
sql
CopyEdit
-- Create Employee Table
CREATE TABLE Employee (
EmployeeID INT PRIMARY KEY,
Name VARCHAR(50),
fi
DepartmentID INT
);
4. What are nested queries and subqueries in SQL? Write examples showing
both correlated and non-correlated subqueries.
• Correlated Subquery: The inner query refers to columns from the outer query.
Example:
sql
CopyEdit
5. Discuss SQL clauses used for grouping, aggregation, and ordering of records.
Support your answer with SQL examples.
• GROUP BY: Groups rows that have the same values into summary rows, often used with
aggregate functions.
Example:
sql
CopyEdit
-- Grouping and Aggregation
SELECT Department, COUNT(*) AS NumEmployees, AVG(Salary) AS
AvgSalary
FROM Employee
GROUP BY Department
HAVING AVG(Salary) > 50000; -- Filter groups where avg
salary is greater than 50000
-- Ordering results
SELECT Name, Salary
FROM Employee
ORDER BY Salary DESC; -- Sorts employees by salary in
descending order
6. Explain various types of SQL JOINS with syntax and examples: INNER
JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN.
• FROM Employee
fi
• INNER JOIN Department ON Employee.DepartmentID =
Department.DepartmentID;
•
• LEFT JOIN: Returns all rows from the left table and matched rows from the right table. If
no match, NULL is returned for right table.
Example:
sql
CopyEdit
• FROM Employee
• LEFT JOIN Department ON Employee.DepartmentID =
Department.DepartmentID;
•
• RIGHT JOIN: Returns all rows from the right table and matched rows from the left table.
If no match, NULL is returned for left table.
Example:
sql
CopyEdit
• FROM Employee
• RIGHT JOIN Department ON Employee.DepartmentID =
Department.DepartmentID;
•
• FULL OUTER JOIN: Returns all rows when there is a match in either the left or right
table. Non-matching rows from both sides are returned with NULL.
Example:
sql
CopyEdit
• FROM Employee
• FULL OUTER JOIN Department ON Employee.DepartmentID =
Department.DepartmentID;
•
• SQL Views: A view is a virtual table created by a query on one or more tables. It can
simplify complex queries and enhance security by restricting access to certain columns or
rows.
• Updatable Views: A view that allows for INSERT, UPDATE, and DELETE operations.
Example:
sql
CopyEdit
• Non-Updatable Views: A view that does not allow direct modi cation. Typically used when
the view involves multiple tables, joins, or aggregate functions.
Example:
sql
CopyEdit
• UNION
• SELECT Name FROM Contractor;
•
• INTERSECT
• SELECT Name FROM Contractor;
•
• EXCEPT: Returns the records from the rst query that do not exist in the second query.
Example:
sql
CopyEdit
• EXCEPT
• SELECT Name FROM Contractor;
•
• JOINS are used to combine rows from two or more tables based on a related column.
• Set operations (UNION, INTERSECT, EXCEPT) are used to combine or subtract result
sets from two queries.
fi
Unit- 4
2 marks
1. What is the main purpose of normalization in database design?
Normalization is the process of organizing the attributes and tables of a relational database to
minimize redundancy and dependency. The main purpose is to:
• Eliminate data redundancy: Redundant data is stored in multiple places, leading to wasted
storage and potential inconsistencies.
• Ensure data integrity: By breaking down complex tables into smaller, manageable ones,
normalization helps maintain consistency and integrity.
This means that for each EmpID, there will be only one corresponding Name and Salary.
A surrogate key is a unique identi er for a table record that is not derived from the application
data. It is typically a system-generated value, such as an integer or GUID (Globally Unique
Identi er).
When is it used?
• It is used when no natural key (i.e., an attribute that uniquely identi es a record in the real
world) is suitable or when a natural key is too complex.
• Surrogate keys are commonly used in situations where the natural key may change over
time, such as in cases where customer data is updated regularly, and the primary key would
need to be updated as well.
• 1NF (First Normal Form): A relation is in 1NF if it has only atomic (indivisible) values
and each record is unique. No repeating groups or arrays are allowed.
Example:
plaintext
CopyEdit
In this example, PhoneNumbers could store multiple phone numbers for each employee,
which violates 1NF.
• 2NF (Second Normal Form): A relation is in 2NF if it is in 1NF and all non-key attributes
are fully dependent on the primary key. In other words, it removes partial dependency,
where non-key attributes depend only on part of a composite primary key.
Example:
plaintext
CopyEdit
If OrderID and ProductID together form the primary key, and ProductPrice
depends only on ProductID, then ProductPrice is partially dependent on part of
the primary key, violating 2NF.
Lossless Join Decomposition refers to the process of breaking down a relation into smaller sub-
relations in such a way that, when they are joined back, the original relation can be perfectly
reconstructed without any loss of data.
Importance:
• It guarantees that the decomposed relations still provide the original information when
joined together.
Example: Decomposing a table Employee (EmpID, Name, DeptID,
DeptName) into two tables Employee (EmpID, Name, DeptID) and
Department (DeptID, DeptName) maintains the original data when the two are
joined back.
fi
6. What is Boyce-Codd Normal Form (BCNF)?
Boyce-Codd Normal Form (BCNF) is a higher version of the 3NF. A relation is in BCNF if, for
every functional dependency X → Y, the determinant X is a superkey.
A Multivalued Dependency (MVD) occurs when one attribute or set of attributes in a table
uniquely determines a set of values for another attribute, independent of other attributes. It is a type
of dependency that occurs when an attribute is dependent on a set of attributes, but not on a single
attribute.
This means that for each StudentID, the set of Subjects and the set of Hobbies are
independent, and each can have multiple values.
Importance:
• It ensures that the original set of functional dependencies can still be enforced after the
decomposition, making the database easier to maintain and ensuring that the integrity
constraints are preserved.
• Helps in enforcing the correct constraints while performing queries and updates on the
decomposed tables.
Long Answers
• Reduce Redundancy: Repeating groups of data lead to inef cient storage and increased
risk of data inconsistency.
• Improve Data Integrity: By minimizing redundancy, normalization reduces the risk of data
anomalies and ensures that data is consistent and accurate.
• Optimize Queries: A normalized database structure results in faster, more ef cient queries
as data is more logically organized.
Example:
• 1NF (First Normal Form): Ensures that each attribute contains atomic (indivisible) values.
It eliminates repeating groups.
• 2NF (Second Normal Form): Ensures that a table is in 1NF and that all non-key attributes
are fully functionally dependent on the entire primary key (eliminates partial dependency).
• 3NF (Third Normal Form): Ensures that a table is in 2NF and that no transitive
dependencies exist (i.e., non-key attributes should not depend on other non-key attributes).
fi
fi
fi
fi
fi
3. Describe 1NF, 2NF, and 3NF with examples. How does each normal form
eliminate redundancy?
A relation is in 1NF if all the columns contain atomic (indivisible) values, and each record is
unique. No repeating groups or arrays should be present.
Example:
plaintext
CopyEdit
Employee(EmpID, EmpName, PhoneNumbers)
In this example, PhoneNumbers could contain multiple numbers for each employee, violating
1NF. To bring it to 1NF:
plaintext
CopyEdit
Employee(EmpID, EmpName, PhoneNumber)
This ensures that each PhoneNumber is atomic.
A table is in 2NF if it is in 1NF and all non-key attributes are fully functionally dependent on the
entire primary key. It eliminates partial dependency, where a non-key attribute depends only on
part of a composite key.
Example:
plaintext
CopyEdit
OrderDetails(OrderID, ProductID, ProductName, Quantity)
If OrderID and ProductID are the primary key, ProductName depends only on
ProductID, which violates 2NF. To bring it to 2NF:
plaintext
CopyEdit
OrderDetails(OrderID, ProductID, Quantity)
Product(ProductID, ProductName)
3NF (Third Normal Form):
Example:
plaintext
CopyEdit
Employee(EmpID, EmpName, DeptID, DeptHead)
Here, DeptHead depends on DeptID, which is a non-key attribute, violating 3NF. To bring it to
3NF:
plaintext
CopyEdit
Employee(EmpID, EmpName, DeptID)
Department(DeptID, DeptHead)
This eliminates the transitive dependency between DeptID and DeptHead.
A surrogate key is a unique identi er for a record in a table that has no meaningful relationship to
the data in the table. It is typically generated by the database system, often using an auto-
incremented number or a GUID.
• Simpli es Key Structure: Surrogate keys provide a simple, unique identi er, avoiding
complex or composite keys.
• Improves Performance: As surrogate keys are typically small, they reduce the storage
space and improve query performance.
• Preserves Data Integrity: Surrogate keys ensure that the identity of a record is independent
of the business logic.
Example: Instead of using a composite key like (FirstName, LastName), you can use a
surrogate key like EmployeeID.
• Lack of Business Meaning: Surrogate keys don’t carry any business meaning, making it
dif cult for users to understand the data.
• Potential for Redundancy: If the surrogate key is used across many tables, the relationship
between tables may be harder to understand.
5. Explain the Boyce-Codd Normal Form (BCNF). How does it differ from 3NF?
Provide an example to show a relation that is in 3NF but not in BCNF.
Boyce-Codd Normal Form (BCNF) is a stricter version of 3NF. A relation is in BCNF if, for every
functional dependency X → Y, the determinant X is a superkey (a set of attributes that uniquely
identi es a tuple in a relation).
Here, Instructor is not a superkey, so the relation is in 3NF but not in BCNF. To bring it into
BCNF, we decompose it into two relations:
plaintext
CopyEdit
Student(CourseID, Instructor)
InstructorRoom(Instructor, Room)
Lossless Join Decomposition ensures that the original relation can be reconstructed by performing
a natural join of the decomposed relations. This prevents the loss of any data during decomposition.
Dependency Preservation ensures that all functional dependencies are maintained in the
decomposed relations.
Example:
• StuID → Name
• CourseID → Instructor
If we decompose it into:
plaintext
CopyEdit
Student1(StuID, Name, CourseID)
Student2(CourseID, Instructor)
• The join of Student1 and Student2 gives back the original relation, so the
decomposition is lossless.
A multivalued dependency (MVD) occurs when one attribute or set of attributes determines
another set of attributes independently of other attributes in the relation.
plaintext
CopyEdit
StudentSubject(StuID, Subject)
StudentHobby(StuID, Hobby)
5NF (Fifth Normal Form), also called Projection-Join Normal Form (PJNF), is a normal form
in which a relation is decomposed in such a way that it cannot be further decomposed without
losing information. A relation is in 5NF if every join dependency in the relation is implied by the
candidate keys.
Example:
• An employee may work on multiple projects and may have multiple skills.
• If each skill is tied to each project and employee, this can lead to redundant data.
plaintext
CopyEdit
Project(ProjID, EmpID)
EmployeeSkill(EmpID, Skill)
5NF is particularly useful when complex relationships exist, and eliminating redundancy without
losing data requires a detailed decomposition of the data.
fi
Unit-5
2 marks
1. What are the different states of a transaction?
2. Partially Committed: The transaction has completed execution, but changes are not yet
permanent.
3. Committed: The transaction has successfully completed, and changes are permanent.
5. Aborted: The transaction was rolled back and no changes are made.
2. Consistency: The database moves from one consistent state to another after a transaction.
3. Isolation: Transactions are isolated from each other; the intermediate state of a transaction is
not visible to others.
4. Durability: Once a transaction is committed, its changes are permanent, even in case of a
system failure.
Serializability ensures that the concurrent execution of transactions results in a database state
equivalent to some serial (non-interleaved) execution of those transactions. This ensures
consistency, as if the transactions were executed one after another, without interference.
• Deadlock: Occurs when two or more transactions are waiting for each other to release
resources, causing a cycle of waiting where none of the transactions can proceed.
A B+ Tree is a self-balancing tree data structure that maintains sorted data and allows ef cient
insertion, deletion, and search operations. Its primary use in databases is for indexing, allowing
quick data retrieval.
Optimistic concurrency control assumes that multiple transactions can complete without
interfering with each other. It allows transactions to execute without locks, but before committing, it
checks if there were any con icting operations during the transaction's execution. If a con ict is
found, the transaction is rolled back.
2. System Crash: Happens when the DBMS or hardware crashes unexpectedly, causing data
loss or inconsistencies.
Long answers
The ACID properties are the foundation of reliable database transactions, ensuring that database
operations are executed in a consistent and secure manner.
1.1 Atomicity
• Example: In a bank transfer, if a transaction deducts money from one account but fails to
add it to another, the entire transaction is rolled back to maintain consistency. No money is
lost.
• Importance: Atomicity ensures that partial or incomplete transactions don't leave the
database in an inconsistent state.
1.2 Consistency
• De nition: A transaction must bring the database from one consistent state to another,
adhering to all de ned constraints (e.g., uniqueness, foreign keys).
fi
fi
fi
fi
fi
fl
fl
fi
fi
fl
• Example: In a student enrollment system, if a transaction adds a record for a student, it
should ensure that the student ID is unique, and no other student has the same ID.
• Importance: It guarantees that the database maintains integrity by following all de ned
rules.
1.3 Isolation
• De nition: Transactions should not interfere with each other. Even if transactions are
executed concurrently, their results should be as if they were executed serially.
• Example: If two transactions are transferring money between accounts, they should not see
partial or con icting results. One transaction should not be affected by the other until it is
complete.
• Importance: Isolation ensures that one transaction's work is not disrupted by others,
preventing inconsistencies like dirty reads.
1.4 Durability
• De nition: Once a transaction is committed, its changes are permanent, even in the event of
a system failure (e.g., power loss, crash).
• Example: After transferring funds, even if the system crashes, the transaction's changes are
not lost because they have been recorded in stable storage (e.g., disk).
• Importance: Durability guarantees that once a transaction is committed, the changes are
never lost, making the database resilient to failures.
2. Concept of Serializability
Serializability refers to the ability to ensure that concurrent execution of transactions produces the
same result as if the transactions were executed one by one, i.e., serially.
• De nition: A schedule is con ict serializable if it can be transformed into a serial schedule
by swapping non-con icting operations (operations that do not operate on the same data
item).
• Example:
◦ The above schedule is con ict serializable because the operations on A and B do not
interfere with each other and can be swapped.
• Example: If transactions access different data items or read/write the same data item in a
different order but still produce the same result, it is considered view serializable.
• De nition: In lock-based protocols, transactions acquire locks before accessing data. Two
main types of locks:
◦ Exclusive Lock (X-lock): Allows both read and write access to a data item.
• Example: If T1 locks a data item A with an exclusive lock, T2 must wait until T1 releases
the lock before accessing A.
• De nition: Each transaction is given a timestamp. The transactions are executed based on
their timestamps, ensuring that older transactions are given precedence.
• Example: If T1 has a timestamp earlier than T2, then T1 must complete its read and write
operations before T2starts.
• Example: A transaction performs its operations, then checks whether any other transactions
have modi ed the data. If con icts are found, the transaction is rolled back.
Transactions can fail due to various reasons, such as system crashes, disk failures, or transaction
errors. Recovery techniques ensure that the database remains in a consistent state.
• Log-based Recovery: A log records every transaction and its changes. After a failure, the
system uses the log to undo incomplete transactions or redo committed transactions.
• Checkpointing: The system periodically saves the state of the database, which can speed up
recovery.
5. Deadlock in DBMS
A deadlock occurs when two or more transactions are waiting inde nitely for each other to release
resources, causing a cycle.
• Technique: The DBMS periodically checks for cycles in the transaction wait-for graph to
detect deadlocks. If a cycle is detected, transactions involved in the cycle are aborted.
• Technique: Deadlock prevention involves ensuring that transactions acquire all necessary
locks at once, or they follow a strict ordering to avoid cycles in the wait-for graph.
Recoverability ensures that a transaction's changes are consistent and can be safely rolled back if
needed.
• De nition: When a transaction fails, all dependent transactions must also be rolled back,
which can lead to a cascading effect if there are multiple dependent transactions.
7. Structure of a B+ Tree
A B+ Tree is a self-balancing tree structure used for indexing in databases. It stores data in leaf
nodes, with internal nodes only used for navigation.
7.1 Insertion
• Steps:
fi
fi
1. Traverse the tree to nd the appropriate leaf node.
3. If the leaf node is full, split it and propagate the split upwards.
7.2 Deletion
• Steps:
6. If the leaf node becomes under lled, borrow a key from a sibling or merge with a
sibling.
• De nition: Uses a hash function to map data to a speci c location in the index. It is optimal
for equality searches.
• Example: A hash index on employee IDs will quickly locate an employee’s data.
• De nition: Uses a tree structure (e.g., B+ Tree) to index data. It supports ef cient range
queries and ordering.
• Example: A tree-based index on employee salaries allows ef cient range queries, such as
nding employees earning between $50,000 and $100,000.
8.3 Differences