How to describe Data consistency in better way

Posted by

[ Data Consistency in DB2 ]
[ Data Consistency in DB2 ]
What data consistency is – in many occasions, single user and multi user environments, put DB2 in data consistency issues.

Let me explain in simple way – The best way to answer that question is by looking at an example:

Suppose a company that owns a chain of restaurants uses a database to keep track of, among other things, the inventory at each restaurant. The database contains inventory tables for every restaurant in the chain and as a restaurant receives and uses supplies, its corresponding inventory table is updated.

Now, suppose a case of coffee is physically moved from one restaurant (which has plenty of coffee in stock) to another (which has just run out). To reflect this inventory move, the cans of coffee value stored in the receiving restaurant’s inventory table will need to be raised, and the cans of coffee value stored in the donating restaurant’s table will need to be lowered. If a user raises the cans of coffee value in the receiving restaurant’s table but fails to lower the value in the donating restaurant’s table, the data in the database will no longer be consistent.

The total cans of coffee value for the entire chain is no longer accurate; nor is the cans of coffee value for the donating restaurant.

What happens in single user model

In single-user environments, a database can become inconsistent if a user fails to make the necessary changes (as in the previous example), if the database system crashes while a user or application is in the middle of making changes or if an application terminates prematurely.

What happens in multi user model

In multi-user environments, inconsistency can also occur when several users or applications attempt to access the same data at the same time. For example, given the scenario just presented, if one user queries the database to obtain the cans of coffee count for the receiving restaurant while another user is updating both restaurants’ inventory tables to show that a case of coffee was moved from one restaurant to another before the updates are committed, the query will erroneously indicate that no more cans of coffee are available.