Entity Integrity ensures that the table contains no duplicate records and that the field that identifies each entry is distinct and never null. The Primary Key’s presence is critical to the entity’s integrity. If a primary key is defined for each entity, the entity integrity rule is followed.
In other words, entity integrity requires that the Primary Keys on each instance of an entity be retained, unique, and have values other than NULL.
In his seminal paper, E. F. Codd stipulated that a primary key of an object, or any part of it, could never have a null value. [1] According to the relational model, every relation (or table) must have an identifier, known as the primary key (abbreviated PK), that allows every row of the same relation to be identified by its content, that is, by a unique and minimum value. The PK is a set of attributes that is not empty (or columns). Because each FK matches a preexisting PK, the foreign key (abbreviated FK) follows the same format.
Although most relational databases do not explicitly state that a table must have a Primary Key, it is best practice to create one for each table in the relational architecture.
Examples:
–Table definition – Dept
CREATE TABLE Dept(
DeptNo INT,
DName VARCHAR(14),
Loc VARCHAR(13),
CONSTRAINT pk_Dept PRIMARY KEY (DeptNo) );
— Tabe Definition – Emp:
CREATE TABLE Emp(
EmpNo INT,
EName VARCHAR(10),
Job VARCHAR(9),
Mgr INT,
HireDate date,
Sal INT,
Comm INT,
DeptNo INT,
CONSTRAINT pk_Emp PRIMARY KEY (EmpNo),
CONSTRAINT fk_DeptNo FOREIGN KEY (DeptNo) REFERENCES Dept (DeptNo) );
As you can see, the DeptNo is a primary key in the Dept table, ensuring that each row of a table has a unique and non-null primary key value. Similarly, EmpNo in Emp table.
Hope you find this article helpful.
Happy learning!!
One comment