You are on page 1of 9

Relational Integrity Constraints

Benedict Lim (Satu)

Primary Keys

A primary key is a column (or columns) in a table that uniquely identifies the rows in that table.

Customers
CustomerNo 1 2 3 FirstName John John Paul LastName Black Thompson Thompson

CustomerNo is the Primary Key.

Foreign Key
Foreign keys are columns that point to primary key columns. The foreign key can be used to crossCustomers reference tables.

Primary Key Orders OrderNo 1 2 3 Foreign Key CustomerN o 37 1 24 Customer No Book Genre Science Religion Arts 1 2 3 FirstName John John Paul LastName Black Thompson Thompson

CustomerNo is a foreign key that points to the primary key in the CUSTOMERS table.

Null
Null is used to indicate that a data value does not exist in the database. It is not zero or an empty string

Null is a blank

Integrity constraints
Integrity constraints are used to ensure accuracy and consistency of data in a relational database. There are many types of integrity constraints that play a role in referential integrity. Examples of it will be entity integrity , referential integrity.

Entity integrity
Entity integrity is an integrity rule which states that every table must have a primary key. Columns chosen to be the primary key should be unique and not null

Example of Entity integrity


OrderNo 1 2 3 4 BooksNo 2 1 4 3 CustomerNo 37 14 24 54 Book Genre Science Religion Arts Sports

As OrderNo is the primary key , therefore it must be unique.

Referential integrity
Referential integrity means that the foreign key in any referencing table must always refer to a valid row in the referenced table. Ensures that the relationship between two tables remains synchronized during updates and deletes.

Example of Referential Integritytable. Referenced


Author_id 1 2 3 Author_Name Bobby Gregory Paul Author_id is the foreign key in Referencing Table

Line Broken Referencing Table Author_id 3

BookNo 1

Book_title Three little Pig

2 3

2 3

The boy Memories

You might also like