Difference Between Primary Key and Foreign Key

Primary Key Vs. Foreign Key: Explore the difference between Primary Key and Foreign Key

A primary key is used to assure the value in the particular column is unique. The foreign key provides the link between the two tables. Find out the major difference between primary key and unique key.

What Is Primary Key?

A primary key generally focuses on the uniqueness of the table. It is a column or a set of columns that uniquely distinguishes every row in the database. It means it should not have any duplicate value. Also, it doesn’t contain a NULL value.

What Is Foreign Key?

A foreign key is generally used to build a relationship between the two tables. The major purpose of the foreign key is to sustain data integrity between two separate instances of an entity.

Difference Between Primary Key and Foreign Key

S.No.

Primary Key

Foreign Key

1

A primary key generally focuses on the uniqueness of the table. It assures the value in the specific column is unique.

A foreign key is generally used to build a relationship between the two tables.

2

Table allows only one primary key.

Tables can allow more than one foreign key.

3

The primary key doesn’t allow null values.

Foreign key accepts multiple null values.

4

It can identify the record uniquely in the database table.

A foreign key is a field in the table that is the primary key in another table.

5

In the primary key, the value cannot be removed from the parent table.

In this, the value can be deleted from the child table.

6

Its restriction can be completely defined on the temporary tables.

Its restriction cannot be defined on the global or local temporary tables.

Keep learning and stay tuned to get the latest updates on GATE along with GATE Preparation Books & GATE Answer Key and more.

Leave a Comment

Your Mobile number and Email id will not be published.

*

*