DBMS: SQL, Transaction Processing,
Concurrency & Recovery
1. SQL Queries (Joins, Subqueries, Aggregate Functions)
Tables: STUDENT, COURSE, ENROLLMENT, DEPARTMENT
JOIN Query:
SELECT [Link], [Link], [Link]
FROM STUDENT s
JOIN ENROLLMENT e ON [Link] = [Link]
JOIN COURSE c ON [Link] = [Link];
Aggregate Function:
SELECT CourseID, AVG(Marks) AS AvgMarks
FROM ENROLLMENT
GROUP BY CourseID;
Subquery:
SELECT StudentName
FROM STUDENT
WHERE StudentID IN (
SELECT StudentID FROM ENROLLMENT
WHERE Marks > (SELECT AVG(Marks) FROM ENROLLMENT));
JOIN + Aggregate:
SELECT [Link], MAX([Link])
FROM ENROLLMENT e
JOIN COURSE c ON [Link] = [Link]
GROUP BY [Link];
2. Query Optimization Techniques
Indexing improves search speed
Avoid SELECT * to reduce overhead
Use JOIN instead of subqueries when possible
Efficient WHERE clause filtering
Use indexes on keys and frequently used columns
Avoid redundant conditions
3. Transaction Processing
ACID Properties: Atomicity, Consistency, Isolation, Durability
Transaction States:
Active
Partially Committed
Committed
Failed
Aborted
Terminated
4. Concurrency Control Techniques
Lock-based protocol (Shared & Exclusive locks)
Two-Phase Locking (2PL)
Timestamp Ordering
Multiversion Concurrency Control (MVCC)
5. Deadlock Handling Methods
Deadlock Prevention
Deadlock Detection using wait-for graph
Deadlock Recovery (rollback/abort)
6. Recovery System
Types of Failures: Transaction failure, System crash, Disk failure
Log-Based Recovery uses undo and redo logs.
Checkpoint Mechanism reduces recovery time by saving system state periodically.