Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Entity Integrity Rule in RDBMS
The Entity Integrity Rule in RDBMS states that every table must have a primary key, and the primary key column(s) cannot contain NULL values. This ensures that every row in a table is uniquely identifiable.
Example 1: Student Table
Consider the following Student table ?
| Student_ID (PK) | Student_Name | Student_Awards |
|---|---|---|
| S001 | Alice | Gold Medal |
| S002 | Bob | NULL |
| S003 | Charlie | Silver Medal |
Here Student_ID is the primary key. We cannot use Student_Awards as the primary key since not every student would have received an award (it can be NULL).
Example 2: Employee Table
| Employee_ID (PK) | Employee_Name | Employee_Age | Employee_Location |
|---|---|---|---|
| E001 | John | 30 | New York |
| E002 | Sara | 25 | London |
The primary key is Employee_ID. It must have a unique, non-NULL value for every row.
Entity Integrity Rule Summary
- Every table must have a primary key.
- The primary key must have unique values for each row.
- The primary key cannot be NULL − for example, Employee_ID cannot be null in the Employee table.
- Every entity (row) must be uniquely identifiable.
SQL Example
The following SQL demonstrates entity integrity using the NOT NULL and PRIMARY KEY constraints ?
CREATE TABLE Student (
Student_ID VARCHAR(10) NOT NULL,
Student_Name VARCHAR(50),
Student_Awards VARCHAR(50),
PRIMARY KEY (Student_ID)
);
-- Valid: Student_ID has a value
INSERT INTO Student VALUES ('S001', 'Alice', 'Gold Medal');
-- Invalid: Student_ID is NULL (violates entity integrity)
-- INSERT INTO Student VALUES (NULL, 'Bob', NULL);
-- Error: Column 'Student_ID' cannot be null
Conclusion
The Entity Integrity Rule ensures that every row in a table is uniquely identifiable by requiring a non-NULL, unique primary key. This is a fundamental constraint in RDBMS that prevents duplicate or unidentifiable records in a table.
