Co4, Co5, Co6 Rdbms Assignment Solution
Co4, Co5, Co6 Rdbms Assignment Solution
QUESTION:
1. Define normalization and normalize a student-course table with repeating
groups.
Normalization is the process of organizing the attributes and relations in a database to minimize
redundancy and dependency. It involves dividing large tables into smaller, manageable ones and
defining relationships between them.
This table contains repeating groups because multiple courses are listed for the same student.
Normalized Tables:
Students Table:
Student_I Student_Name
D
101 John
102 Mary
Courses Table:
Enrollment Table:
Student_I Course_ID
D
101 CS101
101 MA101
102 CS101
Example:
Students Table:
Enrollments Table:
An atomic value is a value that cannot be subdivided further. In the context of First Normal
Form (1NF), the requirement is that each column contains only atomic values (no repeating
groups or arrays).
Example:
Student_I Phone_Number
D
101 123-456-7890
101 987-654-3210
5. Define 2NF and normalize a table with composite keys showing partial
dependency removal.
Second Normal Form (2NF) is achieved when a table is in 1NF and all non-key attributes are
fully dependent on the primary key (i.e., no partial dependency).
Example:
After 2NF:
Students Table:
Student_I Student_Name
D
101 John
102 Mary
Courses Table:
Course_ID Instructor
CS101 Dr. A
MA101 Dr. B
Enrollments Table:
Partial Dependency occurs when a non-key attribute depends on part of a composite primary
key, rather than the whole key.
Example:
For the table below, the composite key is (Student_ID, Course_ID), but Instructor depends only
on Course_ID, not the whole key.
Transitive Dependency occurs when a non-key attribute depends on another non-key attribute
through an intermediate attribute.
Example:
Boyce-Codd Normal Form (BCNF) is a stricter version of 3NF where every determinant is a
candidate key. It is applied when there are anomalies that 3NF does not address, specifically
when a non-prime attribute depends on another non-prime attribute.
When applied: BCNF is used to eliminate any remaining redundancy or anomalies that might
still exist after applying 3NF.
9. What is the purpose of Fourth Normal Form (4NF) and when it is applied in
database design?
Fourth Normal Form (4NF) is applied when a table has multi-valued dependencies, i.e., when
one attribute depends on multiple other attributes but is independent of them.
Purpose: To eliminate multi-valued dependencies where one column depends on multiple other
columns.
When applied: Used when a relation has multi-valued dependencies and needs to be broken into
multiple tables to avoid redundancy.
1. Insert Anomaly
An insert anomaly happens when the database design restricts the addition of
new data unless some other unrelated data is also present. This means that you
cannot insert certain data into the database without having to supply additional
data, which might not always be available or relevant.
Example:
Imagine a table storing information about students and their courses in one single
table:
2. Update Anomaly
An update anomaly occurs when data redundancy leads to inconsistent data after
an update. Since the same data is stored in multiple places, updating a single
instance of that data may leave other instances outdated or incorrect, causing
inconsistency.
Example:
Using the same student-course table, suppose Alice’s instructor for Math changes
from "Mr. Smith" to "Ms. Johnson." If the instructor's name is stored redundantly in
multiple rows for different students or courses, and you update the instructor’s
name in only one row but not the others, the database ends up having conflicting
information about who teaches Math. This inconsistency due to partial updates is an
update anomaly.
3. Delete Anomaly
A delete anomaly happens when deleting some data unintentionally removes
additional, important data that should have been retained. This typically occurs
when multiple types of data are stored in the same table and are not properly
separated.
Example:
In the same table, if Alice is the only student enrolled in the Math course, and you
delete her record because she leaves the institution, you may unintentionally delete
all information about the Math course and its instructor as well. Thus, by deleting
one student's data, important course information is lost, leading to a delete
anomaly.
How fourth normal form is different from fifth normal form? Explain both
the forms by giving an example.
Answer:
Fourth Normal Form (4NF) and Fifth Normal Form (5NF) are advanced stages
of database normalization aimed at eliminating specific types of redundancies and
anomalies to ensure data integrity and efficiency in relational database design.
Fourth Normal Form (4NF)
Definition:
A table is in Fourth Normal Form (4NF) if it is already in Boyce-Codd Normal
Form (BCNF) and contains no multi-valued dependencies. A multi-valued
dependency occurs when one attribute in a table uniquely determines multiple
independent values of another attribute, leading to redundant data.
Purpose:
4NF removes redundancy caused by independent multi-valued facts stored in the
same table. It separates these into different tables to avoid duplication and
anomalies.
Example of 4NF Violation:
Student Cour
_ID se
101 Math
101 Physi
cs
2. Student-Hobby Table
Student Hobb
_ID y
101 Painti
ng
101 Music
Suppl Pa Proje
ier rt ct
S1 P1 J1
S1 P2 J1
S2 P1 J1
S2 P2 J2
This represents a three-way relationship. The table can be decomposed into:
1. Supplier-Part
Suppl Pa
ier rt
S1 P1
S1 P2
S2 P1
S2 P2
2. Supplier-Project
Suppl Proje
ier ct
S1 J1
S2 J1
S2 J2
3. Part-Project
Pa Proje
rt ct
P1 J1
P2 J1
P2 J2
Joining these tables reconstructs the original data without redundancy.
1. SQL Injection:
o Threat: SQL injection occurs when an attacker inserts malicious SQL statements
into a query, which can lead to unauthorized access to or manipulation of data.
o Mitigation:
Use parameterized queries or prepared statements, which ensure that
input is treated as data, not executable code.
Implement input validation to reject unexpected input and employ stored
procedures to minimize SQL injection risks.
2. Privilege Escalation:
o Threat: Privilege escalation allows users to gain access rights beyond their
authorization, potentially leading to data corruption, unauthorized access, or
system compromise.
o Mitigation:
Implement role-based access control (RBAC) to define and enforce user
roles and permissions.
Regularly audit user accounts and privileges to ensure that access rights
are in line with job requirements.
3. Data Breaches:
o Threat: A data breach is when unauthorized users gain access to sensitive data,
which can be exploited or stolen.
o Mitigation:
Use encryption for data at rest and in transit to protect sensitive
information.
Access controls should be enforced to limit who can view or alter data.
Implement multi-factor authentication (MFA) for an added layer of
security.
4. Denial of Service (DoS):
o Threat: DoS attacks aim to make a database or service unavailable by
overwhelming it with traffic.
o Mitigation:
Deploy firewalls and intrusion detection systems (IDS) to filter
malicious traffic.
Use load balancing and redundancy to distribute traffic and prevent
single points of failure.
Implement rate-limiting to control how many requests a user can send in
a specific time frame.
5. Insider Threats:
o Threat: Insider threats involve employees or trusted users intentionally or
unintentionally compromising the database's security.
o Mitigation:
Apply the principle of least privilege (PoLP) to limit access rights based
on the specific tasks users need to perform.
Monitor and audit database activities, looking for unusual behavior or
access patterns.
Implement segregation of duties, ensuring no one user can perform
critical actions like modifying both data and the database schema.
6. Unpatched Vulnerabilities:
o Threat: Attackers exploit known vulnerabilities in database software to gain
unauthorized access or execute malicious actions.
o Mitigation:
Keep the database management system (DBMS) and associated
software up to date by applying patches and updates regularly.
Use automatic patch management tools to streamline this process and
reduce the risk of overlooking updates.
7. Weak Authentication:
o Threat: Weak passwords or poor authentication mechanisms can allow
unauthorized users to gain access to the database.
o Mitigation:
Enforce strong password policies (e.g., minimum length, complexity
requirements) and implement multi-factor authentication (MFA).
Use certificate-based authentication or tokenization for high-security
systems.
Q22: How does authentication differ from authorization in terms of user access
control in databases?
In database systems:
Authentication ensures that the database only allows valid users to connect.
Authorization governs what actions authenticated users are allowed to perform (e.g.,
read, write, or modify data).
Q23: What is a distributed database and what are its practical advantages and
disadvantages?
A distributed database is a database that is stored across multiple physical locations, either on
different computers or in multiple data centers, yet is treated as a single cohesive system by users
and applications.
Advantages:
1. Scalability: Distributed databases can easily scale horizontally by adding more nodes
(computers) to the system, which allows for handling larger volumes of data.
2. Reliability and Availability: Since the data is spread across multiple locations, the
system can continue functioning even if one or more nodes fail.
3. Performance: Distributing data allows queries to be processed by the nearest node,
reducing latency and improving response time.
Disadvantages:
Replication and fragmentation are two main strategies used in distributed databases for data
distribution.
Replication: In replication, copies of the same data are stored at multiple locations
(nodes) within the database. This ensures availability and fault tolerance, as the database
can continue to function even if one or more nodes fail.
o Pros: Improved availability, fault tolerance, and read performance since queries
can be served from multiple locations.
o Cons: Increased storage costs and potential issues with data consistency across
replicas.
Fragmentation: Fragmentation involves dividing the database into smaller pieces
(fragments), each stored at different locations. The database can be horizontally
fragmented (dividing data based on rows) or vertically fragmented (dividing data based
on columns).
o Pros: Efficient use of resources, reduced data redundancy, and improved query
performance by limiting data to only what’s necessary at each node.
o Cons: Data retrieval can be slower if fragments need to be recombined from
multiple locations.
Q25: How does fault tolerance play a role in distributed database systems, and
what techniques are used to achieve it?
Fault tolerance refers to the ability of a distributed database system to continue operating
correctly even in the event of hardware failures, network issues, or other unexpected problems.
Concurrency control is crucial in distributed databases to ensure that multiple users or processes
can access the database simultaneously without causing data inconsistencies or conflicts.
Significance:
1. Data Integrity: Concurrency control prevents conflicting operations (e.g., two users
trying to update the same record simultaneously) that could lead to data corruption.
2. Transaction Isolation: It ensures that transactions are isolated from one another,
meaning the intermediate states of one transaction are not visible to others until it is
committed.
3. Deadlock Prevention: Effective concurrency control helps avoid deadlocks, where two
or more transactions are stuck waiting for each other to release resources.
4. Performance: It allows the system to maximize throughput by enabling multiple
transactions to be processed concurrently while ensuring that they do not interfere with
each other.
Common mechanisms:
Horizontal Partitioning:
Definition: Horizontal partitioning divides a database table into rows, distributing the
rows across different nodes. Each partition contains a subset of the total data (e.g., all
customer data from a certain region).
Use Case: Suitable when a table has large numbers of rows and queries commonly
involve a subset of rows.
Advantage: Improved query performance by limiting the amount of data each node must
handle.
Vertical Partitioning:
Definition: Vertical partitioning divides a table into columns, storing each partition on a
different node. Each partition contains a subset of the columns (e.g., storing customer
name and address on one node, and customer transactions on another).
Use Case: Useful when queries tend to access only a small subset of columns in a table.
Advantage: More efficient storage and better query performance when accessing specific
columns.
Q28: What is the role of redo and undo operations in database recovery after a
system crash?
Undo Operations: Undo operations are used to revert changes made by transactions that
were not committed at the time of the crash. These operations ensure that no partial
updates or invalid data are written to the database.
Redo Operations: Redo operations are used to reapply changes from committed
transactions that may not have been written to the database before the crash. They ensure
that the database reflects the final state after the system recovery.
Both redo and undo operations are essential for achieving atomicity (ensuring transactions are
either fully completed or not at all) and durability (ensuring that committed transactions are
permanent even in the event of a crash).
A checkpoint is a mechanism in database systems where the current state of the database (i.e.,
all committed transactions and their changes) is saved to persistent storage. This state becomes a
recovery point.
Challenges:
1. Consistency Across Nodes: In distributed databases, it’s challenging to ensure that all
nodes are in a consistent state after a failure, particularly when nodes may have different
data versions.
2. Network Partitioning: During recovery, the database system must handle cases where
nodes cannot communicate with each other due to network issues. This can lead to
problems with data consistency and availability.
3. Transaction Coordination: Coordinating distributed transactions and ensuring that they
are either fully committed or rolled back across all nodes is complex, especially when
network failures or crashes occur during transaction processing.
4. Replication Issues: Maintaining the consistency of replicas during recovery is
challenging, especially when some replicas are not up to date with others due to failures
or lag in synchronization.
Fragmentation Techniques:
1. Horizontal Fragmentation:
o Definition: Horizontal fragmentation divides a database table into smaller subsets
of rows. Each fragment contains a specific subset of the table’s data based on
some criteria, such as geographic location or customer type.
o Example Scenario: A company operating in multiple countries can use
horizontal fragmentation to store customer data by region (e.g., one fragment for
North America, another for Europe).
o Use Case: Suitable for large tables with a high volume of rows, where data access
is typically based on row-specific criteria.
2. Vertical Fragmentation:
o Definition: Vertical fragmentation divides a table into columns rather than rows.
Each fragment contains a subset of the table’s attributes (columns).
o Example Scenario: A database containing customer information where personal
details (name, address) are stored in one fragment, while transactional data
(purchases, orders) is stored in another.
o Use Case: Ideal when different applications require access to different sets of
columns. For example, analytics applications may only need summary data
(aggregated fields), while transactional applications require detailed records.
3. Hybrid Fragmentation:
o Definition: Hybrid fragmentation combines both horizontal and vertical
fragmentation. This method breaks the data into subsets of rows and columns.
o Example Scenario: A customer database could be fragmented by region
(horizontal) and then by the type of information (vertical), such as having one
fragment with basic personal details and another with transactional history.
o Use Case: Useful in complex systems where both row-based and column-based
access patterns are needed, offering flexibility in data distribution and access.
CO3-LONG ANSWER
QUESTION:
Q44: Explain the concept of data replication in distributed databases. Discuss
the advantages and challenges associated with data replication, and describe
different replication strategies such as full replication, partial replication, and
data partitioning with replication.
Definition: Data replication involves creating and maintaining copies (replicas) of data
across multiple nodes in a distributed database to ensure high availability, fault tolerance,
and improved query performance.
1. Consistency Issues: Keeping all replicas synchronized, especially in systems with high
write operations, can lead to consistency problems.
2. Storage Overhead: Storing multiple copies of the data increases the storage
requirements.
3. Synchronization Overhead: Managing the replication process, especially in large
systems, can introduce overhead in terms of both time and resources.
Replication Strategies:
1. Full Replication:
o Every node in the distributed system holds a full copy of the data.
o Use Case: Suitable for systems with relatively small datasets or when high
availability is a priority, such as in read-heavy applications.
2. Partial Replication:
o Only selected parts of the data are replicated across nodes based on access
patterns or specific requirements.
o Use Case: Ideal for large databases with multiple types of data, where only
certain data subsets are needed on specific nodes.
3. Data Partitioning with Replication:
o Combines both partitioning (splitting the data into fragments) and replication
(keeping copies of data partitions on multiple nodes).
o Use Case: Suitable for large-scale databases where the data needs to be both
partitioned for efficient storage and accessed quickly via replicas.
Q45: Explain the various techniques for the recovery of a database. Take
suitable examples to illustrate your answer.
Q46: Describe the shadow paging technique for crash recovery in DBMS.
Provide examples to illustrate the use of shadow paging in recovering from
system failures.
Definition: Shadow paging is a recovery technique where changes to database pages are
made in a new copy (shadow page) of the database. If a system failure occurs during a
transaction, the original database pages are not affected, and the system can restore to the
shadow pages.
1. When a database page is modified, the system creates a shadow page (a copy of the
original page).
2. The changes are made to the original page, and if the transaction commits successfully,
the shadow page is discarded, and the original page becomes permanent.
3. If a crash occurs before the commit, the system can simply use the unmodified shadow
page during recovery, ensuring no data loss.
Example:
If a customer’s details are updated in a banking database, a shadow page is created for
that record. If the system crashes before committing the update, the original page
(shadow copy) is used to recover the database, avoiding inconsistent data.
Q47: Describe the difference between deferred and immediate database
modification techniques in recovery management.
Q48: Explain the role of recovery management in ensuring fault tolerance and
high availability in DBMS.
1. Fault Tolerance:
o Recovery management ensures that the database can continue operating correctly
after a failure. Techniques such as logging, checkpointing, and replication allow
the system to recover data to a consistent state after crashes or hardware failures.
o By using these techniques, recovery management ensures that data loss is
minimized, and the database can restore to the last known good state.
2. High Availability:
o Recovery management plays a crucial role in ensuring that the database remains
accessible even in the event of failures. Replication and failover mechanisms
allow applications to access data from available replicas during maintenance or
failure events.
o Automated failover and data recovery processes ensure that the system
continues to provide service without significant downtime.
Example: In the case of a database crash, recovery mechanisms like replication and data
restoration from logs ensure that the database remains available to users while also providing
data integrity and consistency.
CO2-SHORT ANSWER
QUESTION:
Q14: What is serializability, and why is it important in concurrent transaction
execution?
Serializability refers to the property of a database system in which the results of executing a set
of transactions concurrently are the same as if they had been executed sequentially, one after
another, without overlapping. It ensures that despite the interleaving of operations from multiple
transactions, the final state of the database will be consistent and correct.
Conflict Operations occur when two transactions access the same data item and at least one of
them is a write operation. These conflicts need to be managed to maintain database consistency.
1. Read-Write (RW):
o Definition: One transaction reads a data item, and another transaction writes to
the same data item.
o Example:
Transaction 1 (T1) reads a bank account balance of $100.
Transaction 2 (T2) writes a new balance of $150 to the same account.
o If T1 reads before T2 writes, the result could be incorrect if the write happens
after the read, as T1 would operate on stale data.
2. Write-Read (WR):
o Definition: One transaction writes to a data item, and another transaction reads
the same data item.
o Example:
T1 writes an updated price of $20 for a product.
T2 reads the price of the same product.
o If T2 reads the old price before T1 writes the new price, it will have outdated
information, leading to inconsistent results.
3. Write-Write (WW):
o Definition: Two transactions write to the same data item.
o Example:
T1 writes a new address for a customer.
T2 writes a different address for the same customer.
o This can lead to data loss or inconsistency since both transactions are changing
the data, but only the last write will persist.
1. Deadlock:
o Deadlock occurs when two or more transactions are waiting for each other to
release locks, causing all involved transactions to be stuck indefinitely.
o Example: T1 locks Resource A and waits for Resource B, while T2 locks
Resource B and waits for Resource A.
2. Starvation:
o Starvation happens when a transaction is perpetually denied access to the data it
needs because other transactions keep acquiring the necessary locks first.
o Example: T1 is constantly waiting for T2 to release a lock, but T2 always gets
priority, preventing T1 from executing.
3. Lock Contention:
o When multiple transactions attempt to acquire the same lock, it can lead to delays
or longer wait times, which negatively impacts performance.
o Example: Multiple users trying to update the same account record may
experience delays due to lock contention.
4. Overhead:
o Locking mechanisms introduce overhead due to the need to maintain and manage
locks on data, potentially reducing system performance.
Q17: What is an inconsistent read problem, and how does it affect transaction
results?
An inconsistent read occurs when a transaction reads a data item that is being modified by
another transaction. The data read might not represent a consistent state, as it could be in the
middle of an update operation or have been partially modified by a transaction.
Starvation:
Deadlock:
Definition: Deadlock occurs when two or more transactions are in a state of waiting for
each other to release resources (locks), resulting in a cycle where no transaction can
proceed.
Example: Transaction T1 locks Resource A and waits for Resource B, while Transaction
T2 locks Resource B and waits for Resource A, causing a deadlock.
Key Difference:
Starvation involves delays without a cycle, and deadlock involves a circular dependency
where all affected transactions are stuck.
Q19: Why is two-phase locking important, and how does it ensure serializability?
Importance of 2PL:
Ensures Serializability: By locking data before performing any operations, 2PL
guarantees that the transaction operations follow a serializable order, preventing
anomalies like lost updates, temporary inconsistencies, and other concurrency-related
problems.
Avoids Conflicts: The restriction of releasing locks after entering the shrinking phase
ensures no conflicts arise from simultaneous transactions modifying the same data.
Q20: What anomaly occurs when a transaction reads the same data twice with
different values?
The anomaly that occurs when a transaction reads the same data twice with different values is
called a non-repeatable read.
Definition: This happens when a transaction reads a data item, and between the two
reads, another transaction modifies that data item.
Example:
o Transaction T1 reads the price of a product, which is $100.
o Transaction T2 then updates the price of the product to $120.
o T1 reads the price again and finds it is now $120, resulting in inconsistency in the
transaction's view of the data.
C02-LONG ANSWER
QUESTIONS:
Q37: Explain the transaction states, also associated with its operations.
1. Serial Schedule:
o Definition: A schedule is serial if the transactions are executed one after the other
without overlapping. In a serial schedule, the operations of one transaction are
completely executed before the operations of the next transaction begin.
o Characteristics: There are no interleaved operations between transactions. It is
the simplest form of transaction scheduling, and the result is always serializable.
o Example: T1 → T2 → T3 (Transaction 1 completes all its operations before
Transaction 2 starts, and Transaction 2 completes before Transaction 3 starts).
2. Conflict-Serializable Schedule:
o Definition: A schedule is conflict-serializable if the transactions in it can be
reordered (by swapping non-conflicting operations) to form a serial schedule
without changing the final result.
o Conflict Operations: Two operations conflict if they access the same data item,
and at least one of them is a write operation. For example, if Transaction T1
writes to data item X, and Transaction T2 reads or writes to X, those operations
are in conflict.
o Steps for Checking Conflict-Serializability:
Create a precedence graph (a directed graph where each node represents
a transaction, and edges represent conflicts).
If the graph contains no cycles, the schedule is conflict-serializable.
If there are cycles, the schedule is not conflict-serializable.
3. View-Serializable Schedule:
o Definition: A schedule is view-serializable if it is possible to transform it into a
serial schedule without altering the final state of the database. This is based on the
idea that the final view (set of data read by each transaction) should be the same
as in some serial execution.
o Characteristics: View serializability is a more relaxed form of serializability than
conflict serializability.
o Checking Procedure: View-serializability requires comparing the read and write
operations of the transactions to ensure that the same final result is achieved as in
a serial schedule.
1. Conflict Graph Construction: Construct a conflict graph by drawing nodes for each
transaction and drawing a directed edge between two transactions if they have conflicting
operations.
2. Check for Cycles: If the graph contains a cycle, the schedule is not conflict-
serializable.
3. Check for Serializability: If there is no cycle in the graph, the schedule is conflict-
serializable.
Q39: Describe the Two-Phase Locking Protocol (2PL), explain both its growing
and shrinking phases, and show how it helps maintain serializability using a
multi-transaction example involving resource locking.
Phases of 2PL:
1. Growing Phase:
o Definition: During this phase, a transaction can acquire locks on data items, but it
cannot release any locks.
o Goal: The goal is for the transaction to acquire all the locks it needs to perform its
operations before it starts releasing locks.
o Example: Consider two transactions, T1 and T2. T1 begins its growing phase by
acquiring a lock on Resource A, then on Resource B, before performing
operations on them.
2. Shrinking Phase:
o Definition: Once a transaction releases a lock, it enters the shrinking phase. In
this phase, the transaction cannot acquire any new locks; it can only release locks.
o Goal: This phase ensures that no other transaction can access the resources locked
by the current transaction once it has started releasing locks.
o Example: After completing operations on Resource A and B, T1 releases the lock
on Resource A and then on Resource B. At this point, T1 is in its shrinking phase.
Example:
By ensuring that transactions either complete fully or are prevented from modifying data after
starting to release locks, the 2PL protocol helps to ensure that the database remains in a
consistent state.
Q40: How can the Lost Update Problem occur in a concurrent system? Describe
this problem with a practical example and suggest how concurrency control
techniques like locking or timestamping can resolve it.
The Lost Update Problem occurs in a concurrent system when two or more transactions
concurrently access the same data and one transaction’s update is overwritten by another
transaction. The update is "lost" because the second transaction does not account for the first
transaction's update.
Example:
In this case, T1's update to $150 is lost because T2 overwrites it with $120. The final state of
the database reflects $120, which is incorrect because T1's update was not taken into account.
1. Locking: One way to resolve this problem is by using locks. By locking the data before it
is read and modified, you can prevent multiple transactions from updating the same data
simultaneously.
o Example: If T1 locks the balance before reading it, T2 will be forced to wait until
T1 finishes its update and releases the lock.
2. Timestamping: The system assigns a timestamp to each transaction. If a transaction tries
to update data that has been modified by a transaction with an earlier timestamp, the
system rejects the update to avoid overwriting the previous transaction's change.
o Example: If T2 tries to update the balance after T1’s update, it is rejected because
T1 has a higher timestamp, indicating that T2’s update should be discarded.
By using either of these techniques, the database can ensure that updates are not lost and data
consistency is maintained.
The Timestamp-based Concurrency Control Algorithm is used to ensure that transactions are
executed in a serializable order based on their timestamps. The idea is to assign a unique
timestamp to each transaction, and the order of execution is determined by these timestamps.
1. Read Rule: A transaction can read a data item only if its timestamp is earlier than the
timestamp of the transaction that wrote to the data item.
o Example: If Transaction T1 (timestamp 1) writes to data item X, Transaction T2
(timestamp 2) can only read X after T1 commits.
2. Write Rule: A transaction can write to a data item only if its timestamp is earlier than the
timestamps of any transaction that has read or written to the data item.
o Example: If Transaction T1 (timestamp 1) writes to X, and Transaction T2
(timestamp 2) also writes to X, T2 will be rejected because its timestamp is later
than T1’s.
Example:
ACID is an acronym for Atomicity, Consistency, Isolation, and Durability, which are the key
properties that ensure the correctness and reliability of transactions in a database management
system.
1. Atomicity:
o Definition: A transaction is an atomic unit of work, meaning it either completes
entirely or not at all. If any part of the transaction fails, the entire transaction is
rolled back.
o Example: In a bank transfer, if $100 is deducted from one account but the credit
operation to another account fails, the entire transaction is rolled back to ensure
no funds are lost.
2. Consistency:
o Definition: A transaction brings the database from one valid state to another valid
state, ensuring that all database rules (e.g., constraints, triggers) are maintained.
o Example: If a transaction violates a database constraint (e.g., a rule that prevents
negative balances), the transaction is aborted, and the database remains consistent.
3. Isolation:
o Definition: The operations of a transaction are isolated from the operations of
other transactions. Even if transactions run concurrently, each transaction operates
as if it were the only one running.
o Example: If two transactions are transferring funds between accounts, they
should not interfere with each other. One transaction's intermediate steps (e.g., an
intermediate balance) should not be visible to others.
4. Durability:
o Definition: Once a transaction is committed, its changes are permanent, even in
the event of a system failure.
o Example: After committing a transaction that updates a bank account balance, the
changes are permanent and will persist even if the system crashes.