HomeInterview QuestionsCan a foreign key have NULL and duplicate values?

Can a foreign key have NULL and duplicate values?

🟢 Easy Conceptual Junior level
1Times asked
Jul 2026Last seen
Jul 2026First seen

💡 Model Answer

Yes, a foreign key column can contain NULL values and duplicate values, but the semantics depend on the database engine and the definition of the foreign key.

  1. NULL values – By default, a foreign key allows NULLs. A NULL indicates that the relationship is unknown or not applicable, and the referential integrity check is skipped for that row. If you want to enforce that every row must reference a parent row, you must declare the foreign key column as NOT NULL.
  1. Duplicate values – A foreign key does not enforce uniqueness on the referencing column. Multiple rows can reference the same parent row, which is common in one‑to‑many relationships. If you need to prevent duplicates, you must add a UNIQUE constraint on the foreign key column or create a composite unique key that includes the foreign key.
  1. Referencing a composite key – If the referenced primary key is composite, the foreign key must match the exact column set and order. NULLs are still allowed unless the columns are defined NOT NULL.

In summary, a foreign key can contain NULLs and duplicates unless you explicitly restrict them with NOT NULL or UNIQUE constraints. The primary purpose of a foreign key is to enforce referential integrity, not uniqueness.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500