7.2 KB · commit 40bb182
| title | T09.2 · Consistency Property |
|---|
← Previous: T09.1: ACID Properties | 🏠 Index | Next: T09.3: Transaction States and Life-Cycle Diagram →
Topic: T09 · Transactions, ACID & Anomalies | Priority: 🟡 Medium Priority | Exam Frequency: 2/7 finals (6 marks: 2019 Q.3(b), 2024 Q.2(c))
Sources: Silberschatz 7e Ch. 17 (§17.1–§17.2, pp. 800–802) · Lecture Deck 07 (Slide 6) · Raidah Class Notes (p. 26)
Consistency: Consistency requires that executing a transaction in isolation preserves database integrity. If the database starts in a valid state that satisfies all integrity rules, it must end in a valid state once the transaction completes.
Consistency Requirement: A transaction must preserve both explicit schema constraints and implicit application invariants. The DBMS integrity subsystem enforces schema rules, while the application programmer is responsible for business logic invariants.
Database consistency operates across two distinct levels:
Explicit Constraints (Enforced by DBMS):
PRIMARY KEY (entity integrity), FOREIGN KEY (referential integrity), data type restrictions, NOT NULL, and CHECK rules (like CHECK (balance >= 0)).Implicit Invariants (Enforced by Application Programmer):
| Constraint Type | Definition | Enforced By | Handling on Violation |
|---|---|---|---|
| Explicit Constraints | Schema DDL rules (PK, FK, CHECK, NOT NULL) | DBMS Engine | DBMS aborts statement or transaction |
| Implicit Invariants | Real-world business rules and math balance | Application Programmer | Undetected by DBMS; creates corrupt data |
A database transaction executes step by step. When updating two related data items, the database enters a temporarily inconsistent state between the first write and the second write.
Let account A have initial balance $1000 and account B have initial balance $2000. The invariant is A+B=3000.
Transaction T1 transfers $50 from A to B:
1.2.3.4.5.6.7.read(A)A:=A−50write(A)[A becomes 950]read(B)B:=B+50write(B)[B becomes 2050]commit| Timeline Point | Account A ($) | Account B ($) | Total Sum (A+B) ($) | Consistency Status |
|---|---|---|---|---|
| Initial State (Before Step 1) | 1000 | 2000 | 3000 | Consistent |
| Intermediate State (After Step 3) | 950 | 2000 | 2950 | Temporarily Inconsistent ($50 appears missing) |
| Final State (After Step 6) | 950 | 2050 | 3000 | Consistent (Restored) |
This temporary inconsistency is completely safe because of two other ACID properties:
Section A · Asked in: 2019 Q.3(b), 2024 Q.2(c) (CO1) · L2 merge (identical question text)
Question (2019 Q.3(b), 2024 Q.2(c)). Explain the consistency property of a database system with a proper example.
Answer.
The consistency property requires that executing a transaction in isolation preserves the consistency of the database. If the database starts in a valid state that satisfies all integrity rules, it must end in a valid state after the transaction completes.
Consistency covers two categories:
CHECK constraints (such as balance >= 0).Let account A have $1000 and account B have $2000. The consistency invariant requires total funds to remain constant:
A+B=1000+2000=3000Transaction T1 transfers $50 from A to B:
← Previous: T09.1: ACID Properties | 🏠 Index | Next: T09.3: Transaction States and Life-Cycle Diagram →