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

A primary key is a unique identifier for each record in a table and is used to enforce referential integrity in relationships between tables. It ensures that each record has a unique identifier and prevents duplicate records. A foreign key, on the other hand, is a field in one table that refers to the primary key of another table. It creates a relationship between the two tables and allows data to be retrieved from one table based on values in another table. In essence, a foreign key creates a link between two tables, while a primary key provides a unique identifier for each record.