Skip to content
We areTOP 1%

What are integrity constraints in DBMS?

EasyConceptKeys & Constraints
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews

Answer

Integrity constraints are rules declared on tables that the DBMS checks on every insert, update and delete, so that invalid data never enters the database.

  • Domain constraints: every value must belong to its column's type and allowed range, enforced with data types, NOT NULL, CHECK and DEFAULT.
  • Entity integrity: every table has a primary key, and primary key values are unique and never NULL.
  • Referential integrity: a foreign key value must match an existing key in the parent table or be NULL.
  • Key constraints: a UNIQUE column cannot contain repeated values.

MySQL ignored CHECK constraints before version 8.0.16; newer versions enforce them.

Example:

CREATE TABLE accounts (
  acc_no  INT PRIMARY KEY,                     -- entity integrity
  owner   VARCHAR(50) NOT NULL,                -- domain
  balance DECIMAL(10,2) CHECK (balance >= 0),  -- domain
  branch  INT,
  FOREIGN KEY (branch) REFERENCES branches(id) -- referential
);
INSERT INTO accounts VALUES (1, 'Asha', -500, 1);  -- rejected by CHECK

More in Keys & Constraints

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account