Database Management System (DBMS) / Relational Model

Entity Constraints

🎯 What is Entity Constraints?

Entity Constraints ensure that each entity (row) in a table is uniquely identifiable and cannot be null or duplicated.

They are one of the most fundamental integrity constraints in a relational database.

Entity Constraint ensures that no primary key attribute of a relation (table) can be null or duplicated.


πŸ”‘ Key Principles of Entity Constraint:

Rule

Explanation

πŸ†” Uniqueness

Each entity (row) must have a unique identifier (Primary Key)

🚫 No NULL values

The Primary Key cannot be NULL, because every record must be identifiable

🎯 Applies to Primary Keys

Entity constraint is enforced through the Primary Key


🧾 Example: Student Table

StudentID (PK)

Name

Age

101

Alice

20

102

Bob

21

NULL ❌

Zara

22

102 ❌

John

23

  • βœ… Rows 1 and 2 are valid

  • ❌ Row 3 violates entity constraint (StudentID is NULL)

  • ❌ Row 4 violates entity constraint (StudentID is duplicate)


⚠️ Why is it Important?

  • Ensures each row is unique

  • Prevents duplicate or missing identifiers

  • Helps relate data across tables reliably using keys

  • Forms the backbone of data integrity


πŸ§ͺ SQL Example:

CREATE TABLE Student (
  StudentID INT PRIMARY KEY, -- Enforces entity constraint
  Name VARCHAR(50),
  Age INT
);
  • PRIMARY KEY ensures StudentID is unique and not null


βœ… Summary:

Feature

Description

🎯 Enforced by

Primary Key

🚫 Not Allowed

NULL or duplicate primary key values

πŸ”’ Purpose

Guarantee each row is uniquely identifiable

πŸ“Œ Applies to

All entity sets (tables) in the relational model