Can you explain the difference between a primary key and a foreign key in database management?

1 Answers
Answered by suresh

Primary Key vs. Foreign Key in Database Management

Primary Key vs. Foreign Key

Primary key and foreign key are important concepts in database management. Here's a brief explanation of the key differences:

Primary Key:

A primary key is a unique identifier for each record in a table. It ensures that each record is uniquely identified and cannot be duplicated. The primary key also helps in enforcing entity integrity within the database.

Foreign Key:

A foreign key is a field in a table that is linked to the primary key of another table. It establishes a relationship between the two tables, allowing for referential integrity. This means that the values in the foreign key must exist in the primary key of the related table, ensuring data consistency.

So, in summary, the primary key uniquely identifies records within a single table, while the foreign key establishes relationships between tables to maintain data integrity.

Answer for Question: Can you explain the difference between a primary key and a foreign key in database management?