What are the key differences between a primary key and a foreign key in a database?

1 Answers
Answered by suresh

Key Differences between Primary Key and Foreign Key in a Database

Key Differences between Primary Key and Foreign Key in a Database

Primary Key:

  • Uniquely identifies each record in a table.
  • Must contain unique values and cannot have NULL values.
  • Usually consists of a single column or a combination of columns.
  • Enforces entity integrity.

Foreign Key:

  • Establishes a link between two tables.
  • References the primary key of another table to maintain referential integrity.
  • Can have duplicate values and can also contain NULL values.
  • Helps in establishing relationships between tables.

In summary, the primary key uniquely identifies records within a table, whereas the foreign key establishes relationships between tables by referencing the primary key of another table.

Answer for Question: What are the key differences between a primary key and a foreign key in a database?