Dbms Qb-Ese With Markings
Dbms Qb-Ese With Markings
5 marks
Q13: Enumerate five key advantages of using a DBMS over a file processing system.
Q14: Define the three levels of database architecture. Describe each level briefly.
Diagram:
pgsql
Q15: Define database schema and instance. Explain their differences with an example.
+----+------+
| ID | Name |
+----+------+
| 1 | Ravi |
| 2 | Asha |
+----+------+
• Data Abstraction is the process of hiding the details of data storage and focusing on
the essential aspects from the user’s perspective.
Levels of Abstraction:
Diagram:
Q18: What tasks are performed by database administrators for managing users?
Q20: Describe how the internal level handles the physical storage of data.
Q22: What are the two types of schemas in databases? Explain with examples.
Difference:
Type Description Example
Logical Defines structure, attributes,
Table definitions
Schema relationships
Physical Indexes, partitions, access
Specifies storage method and format
Schema paths
1. Schema Evolution refers to the ability to change database structure without losing data.
2. Common operations:
a. ALTER TABLE to add/drop/modify columns.
b. RENAME to rename tables/columns.
c. Adding constraints dynamically.
3. Handled with minimal downtime using versioning tools.
4. View definitions can help maintain backward compatibility.
5. Schema evolution must consider:
a. Data migration
b. Query adaptation
c. Application layer updates
Module-2
37.How does conceptual modeling differ from physical modeling?
• Conceptual Modeling: Focuses on high-level data organization and structure.
• Physical Modeling: Describes actual database storage details like file paths and
indexes.
• Conceptual models use ER diagrams, while physical models use tables and keys.
• Conceptual changes are easier to implement than physical ones.
5-Marks
55. Can an EER model manage staff, doctors, and patients in a hospital
database?
57. What are the key steps involved in conceptual database design?
Q61: Discuss the advantages and limitations of using the ER model in database design.
Design an ER model for an online shopping platform that includes customers, products, and
orders. (10 marks)
Advantages:
Limitations:
Entities:
• Customer (customer_id, name, email)
• Product (product_id, name, price)
• Order (order_id, date)
Relationships:
ER Diagram:
A customer can place multiple orders. Each order can include multiple products. OrderDetails
maintains quantity.
Q62: Explain the importance of primary and foreign keys in maintaining data integrity. (10
marks)
1. Primary Key:
2. Foreign Key:
8. SQL Example:
11. In ER modeling:
2. One-to-Many (1:M):
3. Many-to-Many (M:N):
4. ER Diagram:
1. Generalization:
Example:
2. Specialization:
Example:
3. ER Representation:
9. Specialization types:
• Disjoint/Overlapping
• Total/Partial
1. Aggregation:
3. Example Scenario:
4. ER Diagram:
Student -----\
\ works_on
---------> Project
Professor ----/ |
|
sponsored_by
|
Sponsor
6. SQL doesn’t directly support aggregation, but it’s simulated using junction tables.
Q66: Discuss the key features of the EER model. Provide examples for each
feature. (10 marks)
The Enhanced Entity-Relationship (EER) model extends the ER model with advanced
modeling concepts.
1. Specialization
3. Aggregation
5. Inheritance
7. Completeness Constraints
Diagram Example:
Person
/ \
Student Teacher
(disjoint, total)
Q67: Compare the ER and EER models. Discuss scenarios where the EER
model is more beneficial. (10 marks)
1. University Database:
a. Person → Student, Faculty.
b. Teaches relationship has attributes (semester).
2. Hospital:
a. Staff → Doctor, Nurse.
b. Treats between Doctor & Patient, sponsored by Department (aggregation).
3. Inheritance Needed:
a. Vehicle superclass with Car, Bike subtypes.
Entities:
ER Diagram:
Doctor ------\
\
Appointment
/ \
Patient ------
1. Entity Tables:
2. Relationship Table:
Conceptual Modeling:
It is the high-level design of a database that defines entities, relationships, and constraints,
independent of physical details.
Example:
• Conceptual:
o Student, Course, Enrollment (ER Diagram).
• Physical:
Conclusion:
Q71: Define the ER model. Describe its primary components in detail with
examples. (10 marks)
A high-level data model that defines data as entities, attributes, and relationships.
Primary Components:
1. Entities
a. Real-world objects.
b. Example: Student, Course.
c. Types: Strong and Weak Entities.
2. Attributes
a. Properties of entities.
b. Example: name, age.
c. Types: Simple, Composite, Derived, Multivalued.
3. Entity Sets
a. Collection of similar entities.
b. Example: All students form the Student set.
4. Relationships
a. Association between entities.
b. Example: Enrolls (between Student and Course).
5. Relationship Sets
a. Collection of similar relationships.
6. Primary Key
a. Unique identifier for entity.
b. Example: student_id.
7. Cardinality
a. One-to-one, One-to-many, Many-to-many.
8. Participation
a. Total or partial.
9. Generalization/Specialization (EER)
a. Used in complex scenarios.
Diagram Example:
Role of Relationships:
Types:
1. One-to-One
a. One employee has one ID card.
b. Employee -- IDCard
2. One-to-Many
a. One department has many employees.
b. Department -- Employee
3. Many-to-Many
a. Students enroll in many courses, courses have many students.
b. Student -- Enrolls -- Course
Attributes in Relationships:
Participation:
Cardinality Constraints:
Diagram Example:
• DDL (Data Definition Language) defines, modifies, or deletes database structures (e.g.,
tables).
• DML (Data Manipulation Language) handles inserting, updating, and retrieving data.
• Examples of DDL commands: CREATE, ALTER, DROP.
• Examples of DML commands: INSERT, UPDATE, DELETE, SELECT.
74. Explain the purpose of the ALTER TABLE command with an example.
76. Explain the difference between the DELETE and DROP commands.
77. Write the syntax and purpose of the GRANT command in SQL.
80. How does the REVOKE command differ from the GRANT command?
Provide an example.
81. Explain the concept of database constraints. List any three types of
constraints.
82. Explain the use of the GROUP BY clause in SQL. Provide an example
query.
• GROUP BY groups rows that have the same values in specified columns.
• It is often used with aggregate functions.
• Example: SELECT DepartmentID, AVG(Salary)
FROM Employee
GROUP BY DepartmentID;
83. Differentiate between the GROUP BY and HAVING clauses in SQL with
an example.
84. Explain the UNION operator in SQL. How does it differ from the UNION
ALL operator?
85. Demonstrate how to use INSERT INTO command to add data into the
Employee table.
• The INSERT INTO command is used to add data into a table. It can insert data into
specific columns or all columns in a table.
• Syntax:
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
• Key Notes:
Ensure the data types match the column definitions.
When inserting all values for all columns, column names may be skipped:
INSERT INTO Employee VALUES (4, 'Bob White', 40, 70000);
86. Write an SQL query to retrieve all records from Employee where Salary
is greater than 50000.
• Example Query:
SELECT * FROM Employee
WHERE Salary > 50000;
• Explanation:
The * selects all columns from the table.
The WHERE clause filters records where the Salary is greater than 50000.
This method efficiently retrieves specific data without displaying unnecessary rows.
87. Explain how to use the UPDATE statement to modify an existing Salary
for a given EmpID in the Employee table.
• Example Query:
UPDATE Employee
SET Salary = 65000
WHERE EmpID = 2;
• Explanation:
The SET keyword assigns a new value to the Salary column.
The WHERE clause ensures only the employee with EmpID = 2 is updated.
Without the WHERE clause, all records in the table would be updated.
88. What is the purpose of the ALTER TABLE command? Provide an
example using Employee table.
• The ALTER TABLE command is used to modify an existing table's structure. It can:
Drop columns
• Syntax:
• Key Notes:
Always back up data before performing structural changes.
Use ALTER TABLE cautiously as irreversible changes can occur.
89. Define the purpose of the GROUP BY clause in SQL with an example
query on Employee to find the average Salary for each DepartmentID.
• The GROUP BY clause groups rows based on one or more columns and is commonly
used with aggregate functions like AVG(), SUM(), COUNT(), etc.
• Syntax:
SELECT column1, aggregate_function(column2)
FROM table_name
GROUP BY column1;
• Example Query:
SELECT DepartmentID, AVG(Salary) AS Avg_Salary
FROM Employee
GROUP BY DepartmentID;
• Explanation:
The AVG() function calculates the average salary.
The GROUP BY clause groups employees by their DepartmentID.
The AS keyword assigns a custom alias (Avg_Salary) for clarity. I'll continue with the
remaining answers in the same detailed format. Here's the next set:
90. Write an SQL query to use the AVG() function on the Salary column to
calculate the average salary of all employees.
• Example Query:
SELECT AVG(Salary) AS Average_Salary
FROM Employee;
• Explanation:
The AVG() function calculates the average salary across all employee records.
The AS keyword assigns a clear alias name (Average_Salary) to the result.
No WHERE or GROUP BY clause is needed here since we're calculating for all records.
91. Explain the difference between INNER JOIN and LEFT JOIN. Provide
an SQL query that uses LEFT JOIN to retrieve employees along with their
department names.
• INNER JOIN: Returns only the records that have matching values in both tables.
• LEFT JOIN: Returns all records from the left table (e.g., Employee) and matching
records from the right table (e.g., Department). If no match is found, NULL values
are returned for columns from the right table.
• Syntax for LEFT JOIN:
• Example Query:
SELECT E.EmpID, E.Name, D.DepartmentName
FROM Employee E
LEFT JOIN Department D
ON E.DepartmentID = D.DepartmentID;
• Explanation:
The LEFT JOIN retrieves all employee records even if some employees don't belong to
a department.
Non-matching records will show NULL in the DepartmentName column.
The alias E for Employee and D for Department keeps the query concise.
92. Write an SQL query to delete a record from Employee where EmpID =
3.
• Example Query:
DELETE FROM Employee
WHERE EmpID = 3;
• Explanation:
The WHERE clause ensures that only the employee with EmpID = 3 is deleted.
Without the WHERE clause, all records would be deleted, so caution is necessary.
93. Write an SQL query to create a primary key constraint on the EmpID
column of the Employee table.
• A Primary Key uniquely identifies each record in a table and ensures that values in
that column are unique and non-null.
• Syntax (During Table Creation):
CREATE TABLE Employee (
EmpID INT PRIMARY KEY,
Name VARCHAR(50),
Salary DECIMAL(10, 2)
);
• Explanation:
The PRIMARY KEY constraint ensures each EmpID is unique and non-null.
The ALTER TABLE method is used to add a primary key constraint to an existing table.
95. Write an SQL query using HAVING clause to filter the average Salary
above 60000 for each DepartmentID after grouping by DepartmentID.
• The HAVING clause is used to filter grouped records based on aggregate conditions.
• Syntax:
• Example Query:
SELECT DepartmentID, AVG(Salary) AS Avg_Salary
FROM Employee
GROUP BY DepartmentID
HAVING AVG(Salary) > 60000;
• Explanation:
The GROUP BY clause groups records by DepartmentID.
The AVG() function calculates the average salary for each department.
The HAVING clause filters results where the average salary is greater than 60000.
Unlike WHERE, the HAVING clause works after grouping.
96. Write an SQL query that uses DISTINCT to find all unique
DepartmentID values from the Employee table.
• Example Query:
SELECT DISTINCT DepartmentID
FROM Employee;
• Explanation:
The DISTINCT keyword ensures that each DepartmentID appears only once.
Useful when identifying unique values in large datasets.
Q97. Write a query to demonstrate a transaction using COMMIT and ROLLBACK. (10
Marks)
Explanation:
Example:
BEGIN TRANSACTION;
Q98. Define the UNION operator in SQL and explain its purpose with an example. (10
Marks)
Definition:
Syntax:
SELECT column1, column2 FROM table1
UNION
SELECT column1, column2 FROM table2;
Example:
Explanation:
• Returns a list of unique names from both Employees and Managers tables.
Q99. Write an SQL query to join two tables Orders and Customers using the INNER
JOIN clause. (10 Marks)
Query:
Explanation:
Q100. Explain any five string manipulation functions in SQL with suitable examples. (10
Marks)
Use Cases: Formatting output, parsing input data, standardizing case, etc.
Q101. Write SQL commands to: (a) Insert a record into a table (b) Update a record (c)
Delete a record. Explain the significance of each operation. (10 Marks)
b) UPDATE:
UPDATE Students
SET course = 'AI'
WHERE student_id = 101;
Significance: These commands enable CRUD operations essential for database manipulation.
Q102. Explain the role of FOREIGN KEY in relational databases. Write an SQL query
to create a foreign key constraint. (10 Marks)
Definition:
Example:
Explanation:
• Ensures that only valid customer IDs from the Customers table can appear in Orders.
Q103. Discuss the advantages and limitations of using SQL constraints. Provide scenarios
where constraints improve data integrity. (10 Marks)
Advantages:
Limitations:
Scenarios:
Example:
BEGIN;
UPDATE Accounts SET balance = balance - 500 WHERE account_id = 1;
COMMIT; -- Changes saved
BEGIN;
UPDATE Accounts SET balance = balance - 500 WHERE account_id = 1;
ROLLBACK; -- Changes undone
Module-4
• Natural Join: Joins tables using columns with the same name.
• Equi Join: Uses a specified equality condition (=) between any columns.
• Natural join eliminates duplicate columns.
• Example:SELECT * FROM A NATURAL JOIN B;
SELECT * FROM A JOIN B ON A.id = B.ref_id;
5-Marks
SELECT name
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);
SELECT *
FROM employees e1
WHERE salary = (
SELECT MAX(salary)
FROM employees e2
WHERE e2.department_id = e1.department_id
);
SELECT *
FROM (
SELECT department_id FROM employees
) AS SourceTable
PIVOT (
COUNT(department_id)
FOR department_id IN ([101], [102], [103])
) AS PivotTable;
Q134. Discuss the different types of Joins in SQL with suitable examples. (10 Marks)
Definition:
Joins in SQL are used to combine rows from two or more tables based on a related column
between them. They help retrieve meaningful data from normalized databases.
1. INNER JOIN:
a. Returns records that have matching values in both tables.
b. Excludes unmatched rows.
Example:
Example:
Explanation: Shows all employees, including those not assigned to any department.
Example:
Example:
5. SELF JOIN:
a. A table is joined with itself to compare rows within the same table.
6. CROSS JOIN:
a. Returns the Cartesian product of two tables.
b. Every row from the first table is joined with all rows from the second.
Example:
Explanation: Useful for generating combinations, but usually avoided in large datasets.
Conclusion:
Joins are essential for retrieving related data from multiple tables. Proper use of joins improves
data analysis, performance, and query clarity.
Customers Table:
customer_id | name
------------|------
1 | Alice
2 | Bob
3 | Charlie
Orders Table:
Query:
Explanation:
Result:
a) Create a view called HighEarningEmployees for employees earning more than 50,000:
Conclusion: Database security and authorization are critical to maintaining the integrity,
confidentiality, and availability of modern applications.
Q138. Explain the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN, and
FULL JOIN in SQL with examples.
Example Tables:
Customers:
customer_id | name
------------|------
1 | Alice
2 | Bob
3 | Charlie
Orders:
order_id | customer_id
---------|--------------
101 | 1
102 | 2
Q139. Query to find students who scored above the average in ‘DBMS’ subject
Explanation:
Q141. How can privileges be granted to users in SQL? Explain with an example.
Theory:
Syntax:
Example:
Explanation:
Theory:
Syntax:
Example:
Explanation:
Cascading Effect:
• If user1 granted access to another user using WITH GRANT OPTION, revoking
user1’s access may also remove it from those users.
Q143. Define the term Relational Algebra. List its operations and explain each with
examples.
Definition:
Basic Operations:
σ condition (Relation)
A∪B
4. SET DIFFERENCE (−): Returns tuples in one relation but not the other.
A−B
A×B
ρ(Emp, Employees)
Additional Operations:
A⨝B
Example:
Q144. What is Tuple Relational Calculus? How is it different from Domain Relational
Calculus?
• Also non-procedural.
• Uses domain (field) variables.
{<name, salary> | ∃ id ∃ dept (Employees(id, name, salary, dept) AND salary > 50000)}
Difference Table:
Conclusion:
Module-5
2-Marks Questions (4 Points Each)
• Occur when certain attributes cannot be inserted into the database without the presence
of other attributes.
• Happens due to bad database design (e.g., storing customer data in loan table).
• Example: Cannot add a new branch without a loan.
• Violates normalization principles.
• Occur when data is duplicated and a change in one instance requires changes in all
duplicates.
• Failure leads to data inconsistency.
• Example: Changing branch address in one place, not others.
• Indicates poor normalization.
• When the same data exists in multiple places but is not updated uniformly.
• Happens due to redundancy.
• Example: Two customer records with different addresses.
• Leads to reliability issues.
• Reduces redundancy.
• Ensures data consistency.
• Prevents anomalies (insert, delete, update).
• Makes database maintenance easier.
Student Subjects
John Math, Science
• After 1NF:
Student Subject
John Math
John Science
Module-6
2-Marks Questions (4 Points Each)
• Transaction is executing.
• Performing read/write operations.
• Not yet committed or aborted.
• Normal working state.
192.Explain how a transaction transitions from the "Failed" state to the "Aborted" state.
• Active: Read/Write.
• Partially Committed: All steps done.
• Committed: Final commit.
• If error: Failed → Aborted.
• E.g., Fund transfer.
194. What does ACID stand for in transaction management? Explain each
property briefly. (5 marks)
ACID is an acronym that defines key properties for reliable transaction processing in databases:
1. Atomicity
a. Ensures a transaction is treated as a single unit.
b. Either all its operations are executed or none.
c. If a failure occurs, the system rolls back to its previous state.
2. Consistency
a. Ensures the database moves from one valid state to another.
b. All integrity constraints are preserved after the transaction.
3. Isolation
a. Ensures concurrent execution of transactions does not affect individual
transaction outcomes.
b. Transactions appear as though executed serially.
4. Durability
a. Once a transaction is committed, its changes are permanent.
b. Even system failures cannot undo the results of a committed transaction.
5. Importance
a. ACID guarantees the correctness, integrity, and reliability of the database.
1. Definition:
a. A precedence graph (or serializability graph) helps determine if a schedule is
conflict-serializable.
2. Construction:
a. Nodes: Each transaction in the schedule.
b. Edges: From Ti to Tj if an operation in Ti conflicts with and precedes an
operation in Tj.
3. Conflict Types:
a. Read-Write (RW)
b. Write-Read (WR)
c. Write-Write (WW)
4. Serializability Check:
a. If the graph has no cycle, the schedule is conflict-serializable.
b. If there is a cycle, the schedule is not conflict-serializable.
5. Example:
Schedule:
Conflicts:
6. Use:
a. Used in concurrency control to validate transaction schedules.
1. Definition:
a. Two-Phase Locking (2PL) is a concurrency control method to ensure
serializability.
2. Phases:
a. Growing Phase: Transaction can acquire locks but not release them.
b. Shrinking Phase: Transaction can release locks but not acquire any new ones.
3. Locking Rules:
a. All locks must be acquired before any are released.
4. Importance:
a. Guarantees conflict-serializability of schedules.
b. Prevents lost updates and uncommitted data access.
5. Strict 2PL:
a. All exclusive locks held until the transaction commits or aborts.
b. Used for recoverability and ensuring atomicity.
6. Drawbacks:
a. Can lead to deadlocks due to waiting for locks.
b. Requires deadlock detection or prevention mechanisms.
7. Example:
a. T1 locks A, then B (growing), performs actions, then unlocks A, B (shrinking).
8. Role in DBMS:
a. Widely used for maintaining concurrency control and consistency.
198. Discuss any one method for deadlock detection in database systems. (5
marks)
1. Definition:
a. A directed graph where each node represents a transaction.
2. Edge Representation:
a. An edge from Ti → Tj indicates that Ti is waiting for a lock held by Tj.
3. Deadlock Detection Rule:
a. If the graph contains a cycle, a deadlock exists.
4. Construction Steps:
a. Track all transactions and their lock requests.
b. Add edges as transactions wait.
5. Example:
a. T1 waits for T2, and T2 waits for T1 → cycle → deadlock detected.
6. Detection Frequency:
a. Periodically or on lock request.
7. Resolution:
a. Abort one transaction in the cycle to break the deadlock.
8. Advantages:
a. Detects actual deadlocks instead of preventing all waits.
9. Disadvantages:
a. Overhead of graph maintenance and cycle detection.
10. Use in DBMS:
• Common in systems using lock-based concurrency control.
199. Classify the types of failures that occur in database systems. Provide
examples for each. (5 marks)
1. Transaction Failure
a. A single transaction fails due to logical or input errors.
b. Example: Division by zero in a transaction.
2. System Crash
a. The entire DBMS crashes due to power failure, OS crash, etc.
b. Example: Sudden reboot while transactions are running.
3. Disk Failure
a. Physical damage to the disk where data is stored.
b. Example: Hard disk crash leads to loss of database files.
4. Media Failure
a. Irrecoverable storage medium damage.
b. Example: Fire damages the storage device permanently.
5. Application Software Failure
a. Errors or bugs in the application using the DB.
b. Example: App crash during transaction processing.
6. Operating System Failure
a. OS crash impacts database operation.
b. Example: Kernel panic causes DBMS to stop.
7. Concurrency-Related Failures
a. Conflicts due to improper synchronization.
b. Example: Lost updates or dirty reads.
8. Network Failures
a. Interruptions in communication affect distributed DBs.
b. Example: Connection timeout during transaction commit.
9. Buffer Failure
a. Issues in memory buffers due to corruption or overflow.
b. Example: Corrupted cache leads to wrong data writes.
10. Intentional Kill
• A transaction is aborted by the user or admin.
• Example: Admin kills a long-running unresponsive transaction.
1. Definition:
a. Log-based recovery uses a transaction log that records all DB changes.
2. Transaction Log:
a. Contains <Transaction ID, Data Item, Old Value, New Value>
3. Types of Logs:
a. Undo log: Restores old values
b. Redo log: Reapplies new values
4. Importance:
a. Ensures atomicity and durability of transactions.
b. Helps in recovering committed transactions after crash.
5. Working:
a. On crash, DB checks log:
i. Undo uncommitted transactions.
ii. Redo committed ones.
6. Write-Ahead Logging (WAL):
a. Log is written before actual DB changes are made.
7. Checkpoints:
a. Periodic markers to minimize recovery time.
8. Recovery Example:
a. Crash after T1 commits: Log helps redo T1.
b. Crash before T2 commits: Log helps undo T2.
9. Advantages:
a. Fast, reliable, and widely used.
10. Used In:
• All modern DBMSs like MySQL, Oracle, PostgreSQL.
201. Discuss any one method for deadlock detection in database systems.
(Duplicate of Q198)
Here are detailed answers from Q202 to Q217, formatted for 5-mark (~10 points) and 10-mark
(~15–16 points) expectations, based on your Module-6 notes.
202. Classify the types of failures that occur in database systems. Provide
examples for each. (Same as Q199 — 5 marks)
204. Explain the role of checkpoints in recovery. How do they enhance the
recovery process? (5 marks)
1. Definition:
a. A checkpoint is a point in the log where the DBMS writes all in-memory updates
to disk.
2. Purpose:
a. Reduces the amount of log that needs to be scanned during recovery.
3. Types of Checkpoints:
a. Fuzzy Checkpoints (allow ongoing transactions)
b. Sharp Checkpoints (transactions paused)
4. How They Work:
a. Periodically, the system flushes all modified pages and logs “start checkpoint”
and “end checkpoint”.
5. Recovery Benefit:
a. Speeds up recovery by starting log analysis from the last checkpoint.
6. Minimizes Overhead:
a. Avoids scanning the entire log.
7. Used With WAL:
a. Works with write-ahead logging to ensure consistency.
8. Example:
a. If crash occurs after checkpoint, only logs after it are processed.
9. Frequency:
a. Set based on system workload.
10. Enhancement:
• Ensures efficient, faster, and reliable recovery process.
205. Describe the concept of shadow paging and its use in database recovery.
(5 marks)
1. Definition:
a. Shadow paging is a recovery method that avoids logging by maintaining
shadow pages.
2. Structure:
a. Uses a page table to map logical to physical pages.
3. Working:
a. On a write, changes go to a new page.
b. Old (shadow) page is untouched.
4. Commit:
a. On successful commit, page table is updated to new pages.
b. Old shadow page becomes obsolete.
5. Crash Recovery:
a. If crash occurs, use shadow page table to restore.
6. No Undo/Redo Needed:
a. Ensures atomicity without log.
7. Advantages:
a. Simpler recovery, no logs needed.
8. Drawbacks:
a. High overhead due to copying.
b. Poor performance in high-write systems.
9. Use Case:
a. Suitable for small or read-heavy systems.
10. Example:
• Page 5 updated → new page allocated → commit → update page table.
206. Define shared and exclusive locks. Explain their roles in managing
database concurrency. (10 marks)
5. Examples:
a. T1 reads A → S-lock.
b. T2 wants to write A → must wait if T1 holds S-lock.
6. Role in Concurrency:
a. Prevents dirty reads, lost updates.
b. Manages access in multi-user DB environments.
7. Lock Upgrade:
a. S-lock can be upgraded to X-lock.
8. Deadlock Possibility:
a. If improper lock acquisition order.
9. Unlocking:
a. Done at commit or rollback.
10. Integrated with 2PL:
• Works under two-phase locking for serializability.
11. Implementation in DBMS:
• SQL-based DBs use SELECT ... FOR SHARE or FOR UPDATE.
12. Read-Write Conflict Avoidance:
• Locks delay conflicting operations.
13. Blocking and Waiting:
• Managed via lock queues.
14. Ensures Isolation (ACID):
• Critical for transaction isolation level.
15. Performance Balance:
• Careful usage needed to avoid bottlenecks.
207. Discuss the concept of two-phase locking (2PL) and its impact on
ensuring serializability. (10 marks)
1. Definition:
a. A concurrency control protocol that ensures serializability.
2. Phases:
a. Growing Phase: Transaction acquires all required locks.
b. Shrinking Phase: Transaction releases locks; no new locks acquired.
3. Strict 2PL:
a. Locks held till commit/abort → ensures recoverability.
4. Role in Serializability:
a. Enforces conflict-serializability by avoiding conflicting interleavings.
5. Why It Works:
a. Transactions must finish locking before unlocking → linear order.
6. Example:
a. T1: Lock A, Lock B → operate → Unlock A, Unlock B.
7. Cascading Rollback Avoidance:
a. Strict 2PL avoids reading uncommitted data.
8. Drawbacks:
a. May cause deadlocks.
9. Deadlock Handling:
a. Requires timeout, wait-die, or wound-wait strategies.
10. Variants:
• Conservative 2PL (locks acquired before execution begins).
• Rigorous 2PL (all locks released at commit).
11. Locks Used:
• Shared and Exclusive.
12. Enforces Isolation:
• Vital for achieving isolation in ACID.
13. Comparison to Other Protocols:
• Simpler than timestamp ordering but can block more.
14. Widespread Use:
• Implemented in most commercial DBMS.
15. Visualization:
• Helps analyze using schedule timelines.
1. Wait-Die Scheme
• Older transaction wounds (forces abort) younger one holding the lock.
• Younger transaction waits if older is holding lock.
• Ensures progress of older transactions.
3. Based on Timestamps:
a. Each transaction assigned a timestamp at start.
4. Prevents Cycles:
a. No circular waits possible → deadlocks avoided.
5. Fairness:
a. Older transactions prioritized.
6. Aborts Handled Gracefully:
a. Aborted transactions can restart with same timestamp.
7. Drawbacks:
a. Frequent aborts may reduce performance.
8. Used In:
a. Lock-based protocols, 2PL.
9. Example:
a. T1 (older) requests X on A held by T2 (younger):
i. Wait-Die: T1 waits.
ii. Wound-Wait: T2 aborted by T1.
10. Overhead:
• Timestamp maintenance and transaction restart management.
11. Simple Implementation:
• Suitable for systems avoiding complex detection.
12. Preemptive Strategy:
• Proactively avoids deadlocks rather than detecting.
13. Comparison to Detection:
• Prevention avoids overhead of wait-for graph checks.
14. Trade-offs:
• Reduces deadlocks at cost of transaction aborts.
15. Conclusion:
• Both are effective methods to manage concurrency safely.
209 & 214. What is log-based recovery? Discuss its role in ensuring atomicity
and durability. (10 marks — merge of Q209 and Q214)
1.Definition:
a. Log-based recovery uses a transaction log that records all DB changes.
2.Transaction Log:
b. Contains <Transaction ID, Data Item, Old Value, New Value>
3.Types of Logs:
c. Undo log: Restores old values
d. Redo log: Reapplies new values
4.Importance:
e. Ensures atomicity and durability of transactions.
f. Helps in recovering committed transactions after crash.
5.Working:
g. On crash, DB checks log:
i. Undo uncommitted transactions.
ii. Redo committed ones.
6.Write-Ahead Logging (WAL):
h. Log is written before actual DB changes are made.
7.Checkpoints:
i. Periodic markers to minimize recovery time.
8.Recovery Example:
j. Crash after T1 commits: Log helps redo T1.
k. Crash before T2 commits: Log helps undo T2.
9.Advantages:
l. Fast, reliable, and widely used.
10.Used In:
• All modern DBMSs like MySQL, Oracle, PostgreSQL.
11. Ensures Atomicity:
• On failure, incomplete transactions can be undone via undo log.
12. Ensures Durability:
• Committed transaction logs used to redo after crash.
13. Crash Scenarios Handled:
• Power failure, system crash, transaction abort.
14. WAL Principle:
• Guarantees changes logged before actual DB change.
15. Atomic Commit Protocols:
• Integrates with protocols like two-phase commit in distributed DBs.
1. Definition:
a. A checkpoint is a point in the log where the DBMS writes all in-memory updates
to disk.
2. Purpose:
8. Example:
10. Enhancement:
211 & 216. Define shadow paging. Compare its advantages and limitations
with log-based recovery. (10 marks)
• Recovery mechanism where changes are written to a new page instead of overwriting
existing data.
• Maintains two page tables: current and shadow.
• Shadow page table is not modified during transaction execution.
2. Working
3. No Undo/Redo Required
4. Log-Free Operation
5. Simpler design
6. Atomicity ensured
7. No logs = lower logging overhead
8. Faster recovery in simple setups
Limitations
Use Cases
15. Shadow paging is simple and log-free but inefficient for large-scale DBs.
16. Log-based recovery remains the preferred choice in real-world systems.
212 & 217. Explain how recovery mechanisms like shadow paging and log-
based recovery ensure data consistency. (10 marks)
• Ensures that database constraints and transaction rules are not violated even during
failures.
4. Undo/Redo Mechanisms
6. ACID Compliance
15. Shadow paging and log-based recovery both support Atomicity and Durability,
preserving Consistency
16. These mechanisms guarantee database integrity even after system failures
213. Explain the types of failures in database systems. Provide examples for
each type. (10 marks)
1. Types of Failures:
1. Transaction Failure
2. System Crash
3. Media Failure
4. Application Failure
5. Disk Failure
6. Communication Failure
7. Deadlocks or Timeouts
8. Concurrency Anomalies
9. Natural Disasters
• Rare but severe; floods or fires damaging data centers.