Q3: What are the differences between Primary Key, Foreign Key, and Unique Key constraints?
Keys enforce entity integrity and relationship constraints within relational schemas:
- Primary Key: Uniquely identifies each record in a table. Enforces non-nullability and uniqueness. A table can have only one Primary Key (which can be composite).
- Unique Key: Ensures all values in a column or column group are distinct. Allows one or more
NULLvalues (database dependent). - Foreign Key: Maintains referential integrity by linking a column in a child table to the Primary Key or Unique Key of a parent table.
Key Takeaways
- A table has exactly one Primary Key, which strictly forbids NULL values.
- Foreign Keys enforce referential integrity across relational boundaries.