Part 3 of 5 · 1 min read
Consistency
A transaction may only move the database between states that satisfy its declared rules.
Think of an accounting ledger with a rule that every entry must balance to zero across its columns. Any transaction that would leave the ledger out of balance is simply not allowed to complete.
In plain words: consistency guarantees that a transaction only transforms the database from one state satisfying its declared rules, such as constraints covered in Level 2, to another state that also satisfies those rules. Unlike the other three properties, consistency is not purely something the database engine enforces on its own; it depends directly on what rules, such as constraints and triggers, the application and schema designer actually declared. A database can faithfully provide atomicity, isolation, and durability, yet still allow logically wrong data if the relevant constraint was never declared in the first place.
A worked example. A CHECK constraint requiring balance >= 0 enforces one piece of consistency directly; a transaction that would leave a balance negative is rejected before it can commit.
The key lines.
ALTER TABLE accounts ADD CONSTRAINT nonneg_balance CHECK (balance >= 0);
-- consistency: this specific rule is now enforced on every transaction
Consistency
Consistency guarantees a transaction only moves the database between states that satisfy its declared rules, such as constraints; which rules exist depends on what the schema and application actually declare.
Example: a ledger rule requiring every entry to balance to zero, enforced on every transaction, is a consistency rule in action.