DEV Community

Tharunya K R
Tharunya K R

Posted on

Consistency

Consistency means after transaction database must give the correct and valid answer
Example :
if A = Rs 100 , B = Rs 200
Total = Rs 300
After transfer Total = Rs 300
if it is the correct value then it is inconsistency

Create table example

Table Used
CREATE TABLE accounts (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
balance INT NOT NULL CHECK (balance >= 0)
);
balance >= 0

Sample Data

INSERT INTO accounts (name, balance)
VALUES
('Alice', 1000),
('Bob', 500);

Valid Transaction

UPDATE accounts SET balance = balance - 100 WHERE name = 'Alice';

Result

Alice = 900
It is valid

Invalid Transaction

UPDATE accounts SET balance = -500 WHERE name = 'Alice';

Eror Occur Because negative value is occuring

Top comments (0)