Atomicity means:
A transaction is treated as one indivisible unit: either all of it happens, or none of it happens.
The database must never leave a transaction half-applied.
If a transaction contains 5 steps, and step 4 fails, then steps 1, 2, and 3 must also be undone.
The final outcome is only one of these:
There is no valid third state like “partially done”.
Atomicity protects against:
Suppose a money transfer:
If the system crashes after step 1 but before step 2:
Atomicity says nothing about whether the transaction logic is correct business logic.
It only says the logic is applied fully or not at all.
So this transaction can be atomic and still be wrong:
If both statements complete and commit, atomicity is satisfied.
But business correctness may still be broken.
Consistency means:
A transaction must take the database from one valid state to another valid state.
After the transaction finishes, all defined rules must still hold.
Consistency is about preserving the truth of the database according to its rules.
Those rules may include:
Consistency protects the integrity of the data model.
If a transaction would violate a rule, the database must reject it or roll it back.
Suppose the rule is:
Then this is inconsistent:
If department 999 does not exist, consistency is violated.
A database with proper foreign key enforcement will reject it.
Suppose the rule is:
Then this transaction is inconsistent if it makes balance < 0:
If account 1 had only 300, and your rules say negative balances are forbidden, then allowing this would break consistency.
Consistency is about whether the resulting state is valid.
It is not about “all-or-nothing”; that is atomicity.
Was the transaction fully applied or not applied at all?
Is the resulting database state valid according to all rules?
That is the cleanest way to separate them.
Because in practice, when a transaction fails, the database often rolls it back.
That rollback makes it look like atomicity and consistency are the same thing.
But they are not.
Here:
So they cooperate, but they are different.
Think of the transaction as a package.
Atomicity says:
It does not care whether what is inside the package is logically sensible.
Think of the database as a system that must obey rules.
Consistency says:
It does not mainly describe crash recovery or all-or-nothing behavior.
It describes preservation of integrity.
Suppose a transfer transaction has 3 steps:
If step 3 fails and steps 1–2 remain committed, the system is partially updated.
That is an atomicity failure.
Even if the tables still satisfy constraints, the transfer is incomplete.
So the main broken property here is atomicity.
Suppose this transaction runs fully:
Assume your business rule says balances cannot be negative.
This transaction may be perfectly atomic:
But it is inconsistent, because the final data violates the rule.
So atomicity can be satisfied while consistency is violated.
Mostly, yes.
That is an important insight.
The database engine does not invent your business truth by itself.
It enforces the rules that are defined through:
So consistency depends on the set of rules you define.
Some consistency rules are structural and built into the schema:
So consistency is not “just philosophy”; it becomes concrete through enforceable rules.
Usually through:
Usually through:
So: