Code URL : https://programming-4-students.blogsp...
PRIMARY KEY
Definition:
A primary key is a unique identifier for each record (row) in a table.
It ensures that each row can be uniquely identified and retrieved.
Primary keys must contain unique values and cannot have NULL values.
Key Points:
A table can have only ONE primary key.
The primary key can consist of a single column or multiple columns (composite key).
It guarantees the distinctness of each row in the table.
FOREIGN KEY
Definition:
A foreign key is a field (or collection of fields) in one table that refers to the primary key in another table.
It establishes a relationship between two tables by linking them together.
Purpose:
Foreign keys maintain referential integrity between related tables.
They ensure that data remains consistent and connected across different tables.
Usage:
Typically, a foreign key is used to enforce relationships between tables, especially in scenarios like parent-child relationships or associations between entities.