Primary key nullability and necessity:\n“All primary keys are required.”\nDecide if this statement accurately reflects relational rules for primary keys.

Difficulty: Easy

Correct Answer: Correct

Explanation:


Introduction / Context:
The primary key uniquely identifies each row of a table. To perform that role, the key must be present for every row and must be unique. This question checks whether you know that primary key attributes cannot be optional or NULL in a properly defined table.



Given Data / Assumptions:

  • A primary key may consist of one or more columns (composite key).
  • PRIMARY KEY implies NOT NULL + UNIQUE across the key columns.
  • DBMS enforces these constraints when the primary key is declared.


Concept / Approach:
Because the primary key is the row’s identity, it must always be present. Therefore, DBMSs disallow NULL in any primary key column and require that the combined values be unique. “Required” in modeling terms means the attribute cannot be missing; in SQL this is captured via NOT NULL and the PRIMARY KEY constraint. If you need an optional descriptive attribute, do not put it in the primary key; use a surrogate key for identity and alternate keys for business uniqueness as needed.



Step-by-Step Solution:

Declare PRIMARY KEY; the DBMS automatically prohibits NULLs in the key columns.Attempt to insert a row with a NULL key value; the engine rejects it.Attempt to insert a duplicate key; the engine rejects it due to uniqueness.Thus, primary keys are required and non-null by definition.


Verification / Alternative check:
Review vendor docs (PostgreSQL, MySQL, SQL Server, Oracle): all enforce NOT NULL and uniqueness for PRIMARY KEY columns.



Why Other Options Are Wrong:

  • Limiting correctness to “normalized schemas” or “surrogate keys” is unnecessary; the rule is universal.
  • Collation/locale affects ordering and comparisons, not primary key necessity.


Common Pitfalls:
Using a nullable natural key as the primary key; letting business keys change and break foreign keys; omitting a surrogate when natural keys are volatile.



Final Answer:
Correct

More Questions from Data Models into Database Designs

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion