AI InterviewSearch…Search problems, topics, or pages…Ctrl KGet started
Easydbmsconstraintskeys

~60s

PRIMARY KEY against UNIQUE

What distinguishes a PRIMARY KEY constraint from a UNIQUE constraint?

Show the answer and the worked solution

Correct answer: A.

A UNIQUE column may hold NULL, a PRIMARY KEY column may not

Worked solution

  1. Both constraints reject duplicate values, and a table may carry several UNIQUE constraints but only one primary key.
  2. A primary key identifies a row, so its columns are implicitly NOT NULL.
  3. A UNIQUE constraint carries no such rule, so A UNIQUE column may hold NULL, a PRIMARY KEY column may not.

Answer: A UNIQUE column may hold NULL, a PRIMARY KEY column may not.

The idea

Entity integrity is the rule at work: no part of a primary key may be null, because a null cannot identify anything. UNIQUE only promises no two non-null values repeat.

Shortcut. PRIMARY KEY = UNIQUE + NOT NULL, and only one option matches that equation.

Common trap. "Neither allows NULL, and a table may have only one of each" tempts because both reject duplicates, but UNIQUE accepts NULL and a table may carry several UNIQUE constraints.

OS, DBMS & Networks

28 of 40

Level

Easy

Target time

~60s

PRIMARY KEY against UNIQUE — Aptitude Question

PRIMARY KEY against UNIQUE: What distinguishes a PRIMARY KEY constraint from a UNIQUE constraint? Answer and worked solution on CodeKairo.

Question

What distinguishes a PRIMARY KEY constraint from a UNIQUE constraint?

Options

  1. A UNIQUE column may hold NULL, a PRIMARY KEY column may not
  2. A PRIMARY KEY column may hold NULL, a UNIQUE column may not
  3. Both allow NULL values freely
  4. Neither allows NULL, and a table may have only one of each
Show the answer and the worked solution

Correct answer: A. A UNIQUE column may hold NULL, a PRIMARY KEY column may not

Worked solution

  1. Both constraints reject duplicate values, and a table may carry several UNIQUE constraints but only one primary key.
  2. A primary key identifies a row, so its columns are implicitly NOT NULL.
  3. A UNIQUE constraint carries no such rule, so A UNIQUE column may hold NULL, a PRIMARY KEY column may not.

Answer: A UNIQUE column may hold NULL, a PRIMARY KEY column may not.

The idea

Entity integrity is the rule at work: no part of a primary key may be null, because a null cannot identify anything. UNIQUE only promises no two non-null values repeat.

Shortcut. PRIMARY KEY = UNIQUE + NOT NULL, and only one option matches that equation.

Common trap. "Neither allows NULL, and a table may have only one of each" tempts because both reject duplicates, but UNIQUE accepts NULL and a table may carry several UNIQUE constraints.

All OS, DBMS & Networks questions · placement mock tests