Database Consistency and Its Role Within Transactions

Consistency ensures that the structures of a database are logical

Close up of servers on server rack

Maciej Frolow / Getty Images

Database consistency states that only valid data will be written to the database. If a transaction is executed that violates the database's consistency rules, the entire transaction will be rolled back and the database will be restored to its original state. On the other hand, if a transaction successfully executes, it will take the database from one state that is consistent with the rules to another state that is also consistent with the rules.

Database consistency doesn't mean that the transaction is correct, only that the transaction didn't break the rules defined by the program. Database consistency is important because it regulates the data that is coming in and rejects the data that doesn't fit into the rules. 

Consistency rules are often enforced through constraints at a field level. A constraint specifies a rule governing a given record or field-level value.

Example of Consistency Rules at Work

For example, a column in a database may only have the values for a coin flip as "heads" or "tails." If a user were to attempt to put in "sideways," consistency rules for the database would not allow it.

You may have experience with consistency rules about leaving a field on a web page form empty. When a person is filling out a form online and forgets to fill in one of the required spaces, a NULL value goes to the database, causing the form to be rejected until the blank space has something in it. 

Consistency is the second stage of the ACID model (Atomicity, Consistency, Isolation, Durability), which is a set of guidelines for ensuring the accuracy of database transactions.

Was this page helpful?