Skip to content
C

Consistency


Consistency

Definition

Consistency (the C in ACID) guarantees that a transaction takes the database from one VALID state to another valid state — every constraint (NOT NULL, CHECK, FOREIGN KEY, UNIQUE) that held true before the transaction still holds true after it, whether the transaction commits or rolls back.

How It Works

If a CHECK (balance >= 0) constraint exists on accounts, a transaction that would leave any account with a negative balance is rejected — the database refuses to move into that invalid state, preserving consistency. The transaction either completes while respecting every constraint, or it doesn't complete at all (tying back to Atomicity, 22.5, which is part of what makes this possible).

Edge Cases and Pitfalls

  • Consistency in the ACID sense is about respecting the database's OWN declared rules (constraints) — it does NOT mean the data is necessarily "correct" in a real-world business sense beyond what's actually encoded as a constraint; a transaction that's technically ACID-consistent can still represent a business logic mistake the database has no way to detect (see Chapter 10's Business Constraints — only what's actually declared as a CHECK/constraint is enforced).
  • Don't confuse this with the CAP theorem's "Consistency" (Chapter 38), a distributed-systems concept about multiple nodes agreeing on the same data — a completely different, if related-sounding, idea.
  • Consistency is really a joint responsibility: the database enforces whatever constraints you've DECLARED, but designing the RIGHT constraints (matching your actual business rules) is the schema designer's job, not something the database can infer on its own.

Key Takeaways

  • ACID Consistency means every declared constraint holds both before and after a transaction, whether it commits or rolls back.
  • It doesn't guarantee "correctness" beyond whatever constraints are actually declared — undeclared business rules aren't protected.
  • ACID Consistency is a different concept from CAP theorem Consistency, despite the shared name.

Mock Test

  • Consistency - Quick Test

    8 questions on Consistency.

    8 questions · 8 min · Medium
    Start Mock Test