DBMS Mix Pyq Solutions
DBMS Mix Pyq Solutions
🎗 🎗
👇👇👇👇👇👇👇👇👇👇👇👇
KEEP SHARE THIS LINKS
Ans:
Data Abstraction:
The process of hiding irrelevant information at each level of a database is known as data
abstraction. Data abstraction in DBMS is very helpful in dealing with complex database
systems because it breaks the problem into sub-problems, making it easier to manage.
Data Independence:
Data independence is an advantage of having levels of abstraction in a database management
system. It means that data at different levels are independent of each other. So, if we modify the
data at any level, the other levels will not be affected and will continue to work as expected.
Physical Level Independence in DBMS: The physical level is separated from the
logical level.
Logical Level Independence in DBMS: Changes at the logical level will not affect the
view level.
Ans:
Database Users
Database users based on their interaction with a database system.
1. Naive Users
• Characteristics: Unsophisticated users who don’t interact directly with the database but rely
on predefined application programs.
• Examples: A bank teller using a transfer program, or a person accessing their account balance
on a website.
• User Interface: Typically a forms interface, where users input data into fields or read pre-
generated reports.
2. Application Programmers
• Characteristics: Computer professionals who write application programs to interact with the
database. They develop tools and user interfaces for others to use.
• Tools: They use Rapid Application Development (RAD) tools, fourth-generation languages, or
other specialized tools that integrate data manipulation language (DML) with programming
features.
• Examples: Developing software applications like inventory management systems.
3. Sophisticated Users
• Characteristics: Users who don’t write programs but interact with the database through query
languages (e.g., SQL). They typically include data analysts and researchers who need to analyze
and explore data.
• Tools: They use Online Analytical Processing (OLAP) tools to view and manipulate data
summaries, and data mining tools to uncover patterns.
• Examples: An analyst querying a database to explore sales trends by region, product, or other
criteria.
4. Specialized Users
• Characteristics: These users write specialized applications that don’t fit into traditional data-
processing tasks.
• Examples: Applications in fields like computer-aided design (CAD), knowledge bases, expert
systems, and systems for complex data types (e.g., graphics, audio).
Q.3: Discuss 3-Layer Schema Architecture With Diagram? Also Explain What is Data
Independence & Explain It Types ? Overall DBMS Architecture? (M-23,N-23,M-24,N-24)
Ans:
This level describes what data is stored in the database and the relationships among the
data.
It represents the entire structure of the database for a community of users.
It is independent of how data is stored (physical level) and how it is viewed (external
level).
Called the Logical Level.
Describes how the data is actually stored on storage devices like disks.
It includes data structures, indexing, and file organization.
Called the Internal or Physical Level.
� Database (Disk)
The Database Administrator (DBA) plays a crucial role in managing and maintaining a
database system. The responsibilities outlined for a DBA ensure that the system runs smoothly,
data remains secure, and users can efficiently access and modify the database. Here’s a
breakdown of the key functions of a DBA:
1. Schema Definition
• The DBA is responsible for creating the original database schema using Data Definition
Language (DDL).
• The schema defines the structure of the database, including tables, relationships, and
constraints.
• The DBA defines how the data is stored and how it can be accessed efficiently.
• This includes deciding on storage formats, indexing methods, and optimizing access paths.
• As organizational needs evolve, the DBA updates the schema and physical storage structures.
• Tasks include adding new tables, modifying indexes, or restructuring storage for better
performance and scalability.
Ans:
Ans: Note: Separate Entities & Attributes Just Like Other Diagram
OR
1. Patient
Patient(P_ID, P_name, Age, Mob)
o Primary Key: P_ID
2. Doctor
Doctor(D_ID, D_name, Dept, Qualification)
o Primary Key: D_ID
3. Nurse
Nurse(N_ID, N_name)
o Primary Key: N_ID
4. Bills
Bills(B_ID, Transaction_ID, Receipt, P_ID)
o Primary Key: B_ID
o Foreign Key: P_ID → Patient(P_ID)
5. Rooms
Rooms(R_ID, Availability)
o Primary Key: R_ID
Relationships
10. Room_Types
Room_Types(R_ID, Type)
Ans:
1. Account
o Attributes: A_no (Primary Key), Balance
o Relationship: Linked to Account_branch
2. Account_branch
o Attributes: B_city, Assets
o Relationship: Has Accounts and Loans
3. Customer
o Attributes: C_no (Primary Key), C_name, C_city
o Relationships: Depositor and Borrower
4. Loan
o Attributes: L_no (Primary Key), Amt
o Relationship: Linked to Loan_branch
1. Depositor
o Links Customer(C_no) with Account(A_no)
o Relation: Depositor(C_no, A_no) – Composite Primary Key (C_no, A_no)
2. Borrower
o Links Customer(C_no) with Loan(L_no)
o Relation: Borrower(C_no, L_no) – Composite Primary Key (C_no, L_no)
3. Account
o Account (A_no, Balance, B_city) – B_city is a foreign key referencing
Account_branch(B_city)
4. Loan
o Loan (L_no, Amt, B_city) – B_city is a foreign key referencing
Loan_branch(B_city)
5. Branch (or Account_branch and Loan_branch treated together)
o Branch (B_city, Assets)
Q.3: Construct an ER diagram and convert it into a relational model for a company which
has several employees working on different types of Projects. Several employees are
working for one department, every department has a manager. Several employees are
supervised by one employee. Employees have zero or more dependents? (M-23)
Ans:
1. Company
Company(CID PRIMARY KEY, CName)
2. Department
Department(Dept_ID PRIMARY KEY, Dept_Name, CID FOREIGN KEY REFERENCES
Company(CID), Manager_EID FOREIGN KEY REFERENCES Employee(EID))
3. Employee
Employee(EID PRIMARY KEY, EName, Dept_ID FOREIGN KEY REFERENCES
Department(Dept_ID), Supervisor_EID FOREIGN KEY REFERENCES
Employee(EID))
4. Project
Project(PID PRIMARY KEY, PName)
5. Dependent
Dependent(EID FOREIGN KEY REFERENCES Employee(EID), D_Name, D_Relation,
PRIMARY KEY (EID, D_Name))
6. Works_On (M:N relationship between Employee and Project)
Works_On(EID FOREIGN KEY REFERENCES Employee(EID), PID FOREIGN KEY
REFERENCES Project(PID), PRIMARY KEY (EID, PID))
Ans:
Types of Attributes:
2. Composite Attribute:
3. Derived Attribute:
4. Multivalued Attribute:
These can have more than one value for a single entity.
Represented by double ovals in ER diagrams.
Example: A student can have multiple phone numbers or email addresses.
Ans:
Strong Entity
Example:
Consider a Student entity with attributes Student_ID, Name, and DOB.
Here, Student_ID is the primary key and can uniquely identify each student, making it a strong
entity.
Weak Entity
A weak entity is an entity set that does not have sufficient attributes for the unique
identification of its records.
Simply, a weak entity is nothing but an entity set that does not have a primary key
attribute.
It contains a partial key, which helps in identifying a group of entities from the entity
set.
The partial key is represented by underlining with a dashed line.
A double rectangle is used for representing a weak entity set.
Example:
Consider an Order Item entity in an order management system. The entity Order Item might
not have its own unique identifier but is identified in combination with the Order_ID and
Item_Number, forming the partial key.
Here, the Order Item would be a weak entity, and its partial key (Item_Number) would be
underlined with a dashed line.
Q.6: Draw an E-R For Library Management System & Covert into Relational Schema? (D-
23)
Ans:
Relationships:
Login(Staff_ID, Username)
Maintain(Staff_ID, Reader_ID)
Keeps_Track(Staff_ID, Book_ID)
Issue(Reader_ID, ISBN, Issue_date)
Return(Reader_ID, ISBN, Return_date, Fine)
Reserve(Reader_ID, ISBN, Reserve_date)
Published_By(ISBN, Pub_ID)
Q.7: Define With Example Different Types Of Entities in E-R Diagram? (M-24,N-24)
Ans:
Entity
1. An entity is a thing, object, or person in the real world that is distinguishable from other
objects based on the values of the attributes it possesses.
2. An entity is represented by a rectangle in an Entity-Relationship (ER) diagram.
Types of Entities:
Ans:
Natural Join
Conditional Join
EQUI Join
Self Join
Outer Joins:
o Left Outer Join (LOJ)
o Right Outer Join (ROJ)
o Full Outer Join
� Natural Join
Definition:
A Natural Join combines rows from two tables based on all columns having the same names and
values. It removes duplicate columns from the result.
Emp Table:
1 Ram Delhi
2 Varun Chd
3 Ravi Chd
4 Amit Delhi
Dept Table:
D1 HR 1
D2 IT 2
D3 MRKT 2
Output:
1 Ram Delhi D1 HR
2 Varun Chd D2 IT
� EQUI Join
Definition:
An EQUI Join uses a condition based on the equality operator (=) to match rows from two tables.
Emp Table:
1 Ram Delhi
2 Varun Chd
3 Ravi Chd
4 Amit Delhi
Dept Table:
D1 Delhi 1
D2 Pune 2
D3 Patna 2
� Self Join
Definition:
A Self Join is a join where a table is joined with itself to find relationships within the same table.
Study Table:
S1 C1 2016
S2 C1 2016
S3 C2 2017
S3 C3 2017
s_id
S3
Definition:
A Left Outer Join returns all records from the left table and the matched records from the right
table. Unmatched right-side rows return NULLs.
Emp Table:
E1 Varun D1
E2 Amit D2
E3 Ravi D1
E4 Neha
Dept Table:
D1 HR Delhi
D2 IT Hyd
D3 Finance Pune
Output:
E1 Varun HR Delhi
E2 Amit IT Hyd
E3 Ravi HR Delhi
Definition:
A Right Outer Join returns all records from the right table and matched records from the left
table. Unmatched left-side rows return NULLs.
Emp Table:
E1 Varun D1
E2 Amit D2
E3 Ravi D1
Dept Table:
D1 HR Delhi
D2 IT Hyd
D3 Finance Pune
D4 Testing Noida
Output:
E1 Varun HR Delhi
E2 Amit IT Hyd
E3 Ravi HR Delhi
Definition:
A Full Outer Join returns all rows when there is a match in either left or right table. Unmatched
rows will contain NULLs.
E1 Varun HR Delhi
E2 Amit IT Hyd
Ans:
Definition:
Relational Algebra is a formal query language used to retrieve data from relational databases. It
uses a set of operations (operators) to manipulate relations (tables).
Key Points:
2. Derived Operations:
Join ⟕, ⟖,
Left, Right, Full Outer Joins A ⟕ B (Left join)
Variants ⟗
relationships tuples in B
Sure! Let's go through examples of Relational Algebra operations using tables to make the
concepts clear. We'll use two sample relations:
Relation: Employee
1 Alice 10 28
2 Bob 20 35
3 Carol 10 40
4 Dave 30 22
Relation: Department
DeptID DeptName
10 HR
20 IT
30 Marketing
� 1. Select (σ)
Operation:
Result:
2 Bob 20 35
3 Carol 10 40
� 2. Project (π)
Operation:
Result:
Name Age
Alice 28
Bob 35
Carol 40
Dave 22
� 3. Union (∪)
Operation:
EmpID Name
1 Alice
2 Bob
B:
2 Bob
3 Carol
A∪B
Result:
EmpID Name
1 Alice
2 Bob
3 Carol
Operation:
A−B
Result:
EmpID Name
1 Alice
Operation:
Employee × Department
1 Alice 10 28 10 HR
1 Alice 10 28 20 IT
Note: This multiplies every row of Employee with every row of Department.
� 6. Rename (ρ)
Operation:
ρ EmpInfo (Employee)
This renames the "Employee" table to "EmpInfo"
1 Alice 10 28
Operation:
1 Alice 10 28 HR
2 Bob 20 35 IT
3 Carol 10 40 HR
4 Dave 30 22 Marketing
Operation:
A∩B
EmpID Name
2 Bob
� 9. Division (÷)
Suppose:
WorksIn:
EmpID DeptID
1 10
1 20
1 30
2 10
2 30
Departments:
DeptID
10
20
30
Result:
EmpID
Q.3: Write Short Note On Conversion Of Specialization to relational Schema with example
? (M-23,N-23)
Ans:
When converting specialization into a relational schema, there are three main approaches,
depending on design requirements:
� Example:
ER Diagram:
Relational Schema:
Person(EmpID, Name, Age)
Student(EmpID, Branch) -- FK EmpID → Person
Teacher(EmpID, Salary) -- FK EmpID → Person
Relational Schema:
Student(EmpID, Name, Age, Branch)
Teacher(EmpID, Name, Age, Salary)
Relational Schema:
Person(EmpID, Name, Age, Branch, Salary)
Ans:
Ans:
A trigger is a special type of stored procedure that automatically executes or fires when a
specified event (such as INSERT, DELETE, or UPDATE) occurs in the database server.
Triggers are associated with a table and are used to maintain the integrity of the data, enforce
business rules, and perform automatic actions in response to data modifications.
� Syntax of Trigger:
CREATE TRIGGER [trigger_name]
[BEFORE | AFTER]
[INSERT | UPDATE | DELETE]
ON [table_name]
FOR EACH ROW
BEGIN
[trigger_body]
END;
� Explanation of Syntax:
� Example of Trigger:
Scenario:
You want to insert total and average marks automatically into a StudentMarks table when a
new record is inserted.
Create Table:
CREATE TABLE StudentMarks (
RollNo INT,
Name VARCHAR(50),
Subject1 INT,
Subject2 INT,
Subject3 INT,
Total INT,
Average FLOAT
);
Create Trigger:
CREATE TRIGGER CalculateTotalAverage
BEFORE INSERT ON StudentMarks
FOR EACH ROW
BEGIN
SET NEW.Total = NEW.Subject1 + NEW.Subject2 + NEW.Subject3;
SET NEW.Average = NEW.Total / 3;
END;
Ans:
Integrity Constraints
Integrity constraints are a set of rules. It is used to maintain the quality of information.
Integrity constraints ensure that the data insertion, updating, and other processes have to
be performed in such a way that data integrity is not affected.
Thus, integrity constraint is used to guard against accidental damage to the database.
1. Domain constraints
Domain constraints can be defined as the definition of a valid set of values for an
attribute.
The data type of domain includes string, character, integer, time, date, currency, etc. The
value of the attribute must be available in the corresponding domain.
Example:
The entity integrity constraint states that primary key value can't be null.
This is because the primary key value is used to identify individual rows in relation and if
the primary key has a null value, then we can't identify those rows.
A table can contain a null value other than the primary key field.
Example:
1. Insert Constraint:
o You cannot insert a value in the foreign key column of the child table if that
value doesn't exist as a primary key in the master table.
o This ensures that all references are valid.
2. Delete Constraint:
o You cannot delete a row in the master table if that value is being used in the
child table.
o This prevents deleting a record that is still being referenced.
1 Jack 20 11
2 Harry 24 12
3 John 27 15 ❌
4 Devil 30 13
11 Mumbai
12 Delhi
13 Noida
� What’s wrong?
4. Key constraints
Keys are the entity set that is used to identify an entity within its entity set uniquely.
An entity set can have multiple keys, but out of which one key will be the primary key. A
primary key can contain a unique and null value in the relational table.
Example:
5. Check Constraint:
Ensures that the value in a column meets a specific condition or condition set by the user.
It can be used to validate input based on a condition.
Example: CHECK (age >= 18)
Ans:
UPDATE Book
SET cost = cost * 1.10
WHERE title LIKE '%DBMS%';
iii) Find title of all books whose title contains the word ‘System’.
SELECT title
FROM Book
WHERE title LIKE '%System%';
SELECT title
FROM Book
WHERE cost = (SELECT MAX(cost) FROM Book);
Ans:
SQL aggregation function is used to perform calculations on multiple rows of a single column
of a table. It returns a single value.
It is also used to summarize the data.
1. COUNT()
2. SUM()
3. AVG()
4. MIN()
5. MAX()
COUNT FUNCTION
COUNT function is used to count the number of rows in a database table. It can work on
both numeric and non-numeric data types.
COUNT function uses the COUNT(*) that returns the count of all the rows in a specified
table. COUNT(*) considers duplicate and NULL.
Syntax:
COUNT(*)
or
COUNT([ALL|DISTINCT] expression)
Example: COUNT()
SELECT COUNT(*)
FROM PRODUCT_MAST;
Output:
10
SELECT COUNT(*)
Output:
7
SUM Function
SUM function is used to calculate the sum of all selected columns. It works on numeric
fields only.
Syntax:
SUM()
or
SUM([ALL|DISTINCT] expression)
Example: SUM()
SELECT SUM(COST)
FROM PRODUCT_MAST;
Output:
670
SELECT SUM(COST)
FROM PRODUCT_MAST
WHERE QTY > 3;
Output:
320
AVG Function
The AVG function is used to calculate the average value of the numeric type.
AVG function returns the average of all non-null values.
The SQL DISTINCT keyword is used in conjunction with the SELECT statement to
eliminate all the duplicate records and fetch only unique records.
AVG()
or
AVG([ALL|DISTINCT] expression)
Example:
SELECT AVG(COST)
FROM PRODUCT_MAST;
Output:
67.00
MAX Function
Syntax:
MAX()
or
MAX([ALL|DISTINCT] expression)
Example:
SELECT MAX(RATE)
FROM PRODUCT_MAST;
Output:
30
MIN Function
Syntax:
MIN()
or
MIN([ALL|DISTINCT] expression)
Output:
10
Ans:
Tables:
UPDATE Employee
SET city = 'Mumbai'
WHERE empname = 'John';
SELECT empname
FROM Employee
WHERE MONTH(date_of_joining) = 10;
UPDATE Works
SET salary = salary * 1.10
WHERE company_name = 'ABC Corporation';
4. Find all employees who earn more than the average salary of all employees of their
company:
SELECT company_name
FROM Company
WHERE company_name LIKE 'A%';
6. Find all employees in the database who live in the same cities as the companies
for which they work:
SELECT E.empname
FROM Employee E
JOIN Works W ON E.empname = W.empname
JOIN Company C ON W.company_name = C.company_name
WHERE E.city = C.city;
7. Find all employees who earn more than the average salary of all employees of
their company:
1. Find the project number and name for projects with a budget greater than 100,000.
2. Find the employees (name only) in department 'D1' ordered by descending salary.
3. Find all works records where hours worked is less than 10 and the responsibility is
'Manager'.
4. Find the name of employees that are ending with the letter ‘s’.
5. Find the total number of employees.
6. Write the query to increase the salary of the employees by 10%.
7. Find the employee with the maximum salary.
Ans:
1. Find the project number and name for projects with a budget greater than 100,000:
2. Find the employees (name only) in department 'D1' ordered by descending salary:
SELECT ename
FROM employee
WHERE dno = 'D1'
ORDER BY salary DESC;
3. Find all works records where hours worked is less than 10 and the responsibility is
'Manager':
SELECT ename
FROM employee
WHERE ename LIKE '%s';
UPDATE employee
SET salary = salary * 1.10;
SELECT *
FROM employee
WHERE salary = (SELECT MAX(salary) FROM employee);
Ans:
What is Normalization?
Rule: Each column must contain atomic (indivisible) values, and each record must be
unique.
Goal: Remove repeating groups or arrays.
Problem: The Subjects column contains multiple values, which is not atomic.
Converted to 1NF:
Now, each cell contains atomic values and there are no repeating groups.
Rule: Be in 1NF and remove partial dependency (non-key columns must depend on the
whole primary key).
Problem: CourseName depends only on CourseID, not on the full key (StudentID, CourseID).
This is a partial dependency.
Convert to 2NF:
Enrollment Table:
StudentID CourseID
1 C101
1 C102
2 C101
Course Table:
Rule: Be in 2NF and remove transitive dependency (non-key attributes must not depend
on other non-key attributes).
Goal: Non-key fields should depend only on the primary key.
Convert to 3NF:
Student Table:
StudentID Department
1 Science
2 Math
Department Table:
Department DeptHead
Science Dr. Smith
Math Dr. Johnson
Now, non-key attributes (DeptHead) only depend on the primary key (Department).
Problem: Course → Instructor, but Course is not a candidate key. This violates BCNF.
Fix (BCNF):
Course-Instructor Table:
Course Instructor
DBMS John
DBMS Mike
Course-Room Table:
Problem: The Student table has two independent multi-valued attributes (Course and Hobby),
which should be separated.
Convert to 4NF:
Student-Course Table:
Student Course
Alice Math
Alice Science
Bob Math
Bob English
Student-Hobby Table:
Student Hobby
Alice Reading
Alice Painting
Bob Swimming
Bob Singing
Ans:
Step-by-step analysis:
1. Determine if X → Y
2. Determine if X → Z
X1 maps to Z1
X2 maps to Z1
→ Both consistently map to Z1.
❌ X → Z is valid.
3. Determine if Y → Z
Y1 → Z1
Y2 → Z1
→ All Y values map to Z1.
❌ Y → Z is valid.
4. Determine if Z → Y or Z → X
5. Determine if (X,Y) → Z
6. Determine if (X,Y) → X or Y
X→Z
Y→Z
(X,Y) → Z
(X,Y) → X (trivial)
(X,Y) → Y (trivial)
Ans:
Normalization is essential in database design to ensure data integrity, reduce redundancy, and
improve efficiency. Here's why normalization is needed:
Example: Changing a customer’s phone number in one place but forgetting to update it
elsewhere.
Normalization ensures a single source of truth, avoiding inconsistent updates.
Without normalization: You may not be able to insert data unless other data is also
available.
With normalization: Related data is split into logical tables, allowing independent
insertion.
Example: Deleting a student record also deletes the last record of a course.
Normalization helps preserve essential information by separating related data.
Ans:
Ans:
1. Partial Dependency
Example:
In R(StudentID, CourseID, StudentName),
StudentName depends only on StudentID → Partial Dependency.
2. Transitive Dependency
Example:
If StudentID → DeptName and DeptName → HOD,
Then StudentID → HOD (transitive).
Notation: B ↠ A
Example:
If a student can have multiple phone numbers and multiple hobbies,
StudentID ↠ PhoneNumber and StudentID ↠ Hobby
4. Join Dependency
Definition: A join dependency occurs when a relation R can be reconstructed by joining multiple
smaller relations without data loss.
Example:
Used in 5NF, where the relation is decomposed into 3 or more tables and then joined back
without loss.
Ans:
Deadlock in DBMS
A deadlock is a condition where two or more transactions are waiting indefinitely for one
another to release locks. As a result, no transaction can proceed.
Example:
Transaction T1 locks rows in the Student table and wants to access Grade.
Transaction T2 locks rows in the Grade table and wants to access Student.
T1 waiting for T2
T2 waiting for T1
There are three main strategies to handle deadlocks: Deadlock handling in DBMS refers to the
methods used to prevent, avoid, or resolve deadlocks.
Q.2: What is Two Phase Locking? Explain Its types? Concurrency Control Protocol ? (N-
22,M-23,N-23)
Ans:
Introduction:
Two-Phase Locking (2PL) synchronizes reads and writes by explicitly detecting and preventing
conflicts between concurrent operations.
Conflicting Locks:
RW Synchronization:
Two locks conflict if:
o Both operate on the same data item.
o One is a read lock, the other is a write lock.
WW Synchronization:
Two locks conflict if:
o Both operate on the same data item.
o Both are write locks.
1. Growing Phase:
o Transaction can acquire new locks.
o Cannot release any lock.
2. Shrinking Phase:
o Transaction can release locks.
o Cannot acquire new locks.
The lock point marks the transition from growing to shrinking phase.
All locks are released automatically when the transaction terminates (commit/abort).
Holds both shared and exclusive locks until the transaction commits.
Prevents cascading rollbacks.
Transactions can be serialized in commit order.
Common in database systems.
Ans: Serializability is the concept in database systems that ensures the correctness of
transactions executed concurrently. It guarantees that the final outcome of executing multiple
In simpler terms, serializability ensures that even when transactions run concurrently, the result
will be consistent, and there will be no data anomalies like lost updates or inconsistent reads.
1. Conflict Serializability
Conflicting Operations:
Conflict Pairs:
R-W (Read-Write)
W-R (Write-Read)
W-W (Write-Write)
Example:
Schedule:
T1: R(A), W(A),R(B)
T2: R(A)
If this schedule creates a cycle in the precedence graph, it is not conflict serializable.
If the precedence graph has no cycles, then the schedule is conflict serializable.
2. View Serializability
1. Initial Reads Match: The first read of each data item must be from the same transaction
in both schedules.
2. Write-Read Correspondence: If a transaction reads a value written by another, this
must be preserved.
3. Final Writes Match: The final write on each data item must be by the same transaction
in both schedules.
Example:
Schedule S1:
T1: W(A)
T2: R(A)
T3: W(A)
Schedule S2 (Serial):
T1: W(A)
T2: R(A)
T3: W(A)
Ans:
1. Atomicity means that the entire transaction takes place at once or doesn't happen at all. A
transaction does not occur partially.
2. It involves two operations:
o Abort: Changes made to the database are not visible.
o Commit: Changes made are visible.
2. Consistency
This means that integrity constraints must be maintained so that the database is consistent before
and after the transaction. It refers to the correctness of a database.
3. Isolation
This property ensures that multiple transactions can occur concurrently without leading to the
inconsistency of the database state. Transactions occur independently without interference.
4. Durability
This property ensures that once the transaction has completed execution, the updates and
modifications to the database are stored and written to disk, and they persist even if a system
failure occurs. These updates now become permanent and are stored in non-volatile memory.
The effects of the transaction are never lost.
Ans:
Transaction states
Active state
The active state is the first state of every transaction. In this state, the transaction is being
executed.
For example: Insertion or deletion or updating a record is done here. But all the records are still
not saved to the database.
Partially committed
In the partially committed state, a transaction executes its final operation, but the data is still not
saved to the database.
In the total mark calculation example, a final display of the total marks step is executed in this
state.
Committed
A transaction is said to be in a committed state if it executes all its operations successfully.
In this state, all the effects are now permanently saved on the database system.
Aborted
If any of the checks fail and the transaction has reached a failed state, then the database recovery
system will make sure that the database is in its previous consistent state. If not, then it will abort
or roll back the transaction to bring the database into a consistent state.
If the transaction fails in the middle of the transaction, then before executing the transaction, all
the executed transactions are rolled back to their consistent state.
After aborting the transaction, the database recovery module will select one of the two
operations:
1. COMMIT:
o Purpose: Saves all changes made in the current transaction.
o Syntax: COMMIT;
2. ROLLBACK:
o Purpose: Undoes changes made in the current transaction.
o Syntax: ROLLBACK;
3. SAVEPOINT:
o Purpose: Sets a point to roll back to within a transaction.
o Syntax: SAVEPOINT savepoint_name;
4. SET TRANSACTION:
o Purpose: Configures transaction properties like isolation level.
o Syntax: SET TRANSACTION ISOLATION LEVEL level;
These commands help manage and control database transactions, ensuring ACID properties.
Ans:
Log-Based Recovery
The log is a sequence of records. A log of each transaction is maintained in some stable storage
so that if any failure occurs, it can be recovered from there.
But the process of storing the logs should be done before the actual transaction is applied in the
database.
Let’s assume there is a transaction to modify the City of a student. The following logs are
written for this transaction:
In deferred modification, the transaction does not modify the database until it has
committed.
All the logs are created and stored in stable storage, and only when the transaction
commits is the database updated.
In immediate modification, the database is modified while the transaction is still active.
Here, the database is modified immediately after each operation.
1. If the log contains the records <Ti, Start> and <Ti, Commit> or <Ti, Abort>,
then Transaction Ti needs to be redone.
Note: It is quite time-consuming to redo all the transactions that are committed, so the concept of
checkpoint occurs.
Ans:
Deadlock Prevention
Deadlock prevention method is suitable for a large database. If the resources are allocated in
such a way that deadlock never occurs, then the deadlock can be prevented.
The Database Management System analyzes the operations of the transaction whether they can
create a deadlock situation or not. If they do, then the DBMS never allows that transaction to be
executed.
Wait-Die Scheme
In this scheme, if a transaction requests for a resource which is already held with a conflicting
lock by another transaction, then the DBMS simply checks the timestamp of both transactions. It
allows the older transaction to wait until the resource is available for execution.
Let’s assume there are two transactions Ti and Tj, and let TS(T) be the timestamp of any
transaction T.
Wound-Wait Scheme
In this scheme, if the older transaction requests for a resource held by a younger transaction, then
the older transaction forces the younger one to abort and release the resource.
After a delay, the younger transaction is restarted with the same timestamp.
Q.8: Give example of serial schedule and equivalent to serial schedule with respect to
conflict serializability. ? (M-23,N-24)
Ans:
Serial Schedule
A serial schedule is a type of schedule where transactions are executed one after another, without
any interleaving of operations from different transactions.
Schedule S1:
T1: Read(A) → Write(A)
T2: Read(B) → Write(B)
In this schedule, T1 completes all its operations before T2 starts. This is a serial schedule.
Schedule S2:
T1: Read(A)
T2: Read(B)
T1: Write(A)
T2: Write(B)
Ans:
Key Concepts
Scenario:
Step-by-Step:
Result:
Solution:
Q.10: Explain Concurrency Control & Explain Timestamp Based Protocol ? (M-24,N-24)
Ans:
Key Components: