To ensure consistency in databases, before, during and after read or write operations, certain principles are followed. These are known as ACID properties.
Atomicity means that the entire transaction or operations either takes places at once or does not occur at all. Hence, transactions cannot be just partially fulfilled. This is also known as the "All or Nothing Rule".
A common example is when we initiate a transfer of money between 2 accounts. We cannot have a transaction where we only deducted the money but we did not deposit it into the destination account. Atomicity ensures that the transaction is completed fully and hence helps achieve a consistent database state.
Consistency principle ensures that the integrity of the database is consistent before and after transactions. When interruptions to the transactions occur, the database is rolled back to a previous saved state.
This property ensures that multiple transactions can occur concurrently without causing any inconsistencies. Hence, changes being made by a transaction will not be visible to any other transaction until the current transaction completes successfully.
This property ensures that once a transaction has completed successfully, the modifications are saved and written to disk. This ensures that even in the case of a system failure, the data and modifications and the database state is maintained intact.