In the relationaltonal database key is the most important element to maintain the relationship between two tables or to uniquely identify data from the table. Primary key is used to identify data uniquely therefore two rows can’t have the same primary key. It can’t be null.
On the other hand, foreign key is used to maintain relationship between two tables. Primary of a table act as forgein key in the other table. Foreign key in a table enforce Referential Integrity constraint. It can be more than one in the table.
|Sr. No.||Key||Primary Key||Foreign Key|
It is used to uniquely identify data in the table
It is used to maintain relationship between tables
It can’t be null
It can accept the null values
Two or more rows can’t have same primary key
It can carry duplicate value for a foreign key attribute
Primary has clustered index
By default, It is not clustered index
Primary key constraint can be defined on temporary tables
It can’t be defined on temporary tables