Keys are basic elements of the database relation, as they give a relationship between two tables and make sure that each record in a table is defined uniquely. Keys are one main table-level integrity component, and also help in Referential Integrity. In this article, the primary key and foreign key will be discussed. They actually help fetch data from a number of records stored in a table. In a relational database, the primary key happens to be a special key that helps to identify each record in a table with unique value across each row of the table.
On the other hand, a foreign key happens to be a field in a table, and it links two tables together. It refers to a group of columns or column itself which identifies the row of the table or another one uniquely. Another main difference between these keys is that NULL values can also be contained in foreign keys, while only a primary key can be contained in one relational database without allowing NULL values.