Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a database support "Atomicity" but not "Consistency" or vice-versa?

I am reading about ACID properties of a database. Atomicity and Consistency seem to be very closely related. I am wondering if there are any scenarios where we need to just support Atomicity but not Consistency or vice-versa. An example would really help!

like image 602
rkg Avatar asked Sep 29 '10 05:09

rkg


People also ask

What will happen if atomicity and consistency is not followed in a database?

Thus, when a database processes a transaction, it is either fully completed or not executed at all. If a single portion of the transaction fails, the whole transaction will fail.

How does the database maintain consistency?

Database consistency is achieved by establishing rules. Any transaction of data written to the database must only change affected data as defined by the specific constraints, triggers, variables, cascades, etc., established by the rules set by the database's developer.

How does the database ensure atomicity and durability?

In order to maintain the atomicity of the transactions, it should either complete the transaction (T3 and T4) or rollback the transactions (T1 and T2). But durability of the system is achieved only by completing T3 and T4. i.e.; transaction T2 has already given money to the user and it cannot be rolled back.

What is atomicity in database?

Atomicity means that multiple operations can be grouped into a single logical entity, that is, other threads of control accessing the database will either see all of the changes or none of the changes.


1 Answers

They are somewhat related but there's a subtle difference.

Atomicity means that your transaction either happens or doesn't happen.

Consistency means that things like referential integrity are enforced.

Let's say you start a transaction to add two rows (a credit and debit which forms a single bank transaction). The atomicity of this has nothing to do with the consistency of the database. All it means it that either both rows or neither row will be added.

On the consistency front, let's say you have a foreign key constraint from orders to products. If you try to add an order that refers to a non-existent product, that's when consistency kicks in to prevent you from doing it.

Both are about maintaining the database in a workable state, hence their similarity. The former example will ensure the bank doesn't lose money (or steal it from you), the latter will ensure your application doesn't get surprised by orders for products you know nothing about.

like image 162
paxdiablo Avatar answered Oct 24 '22 14:10

paxdiablo