CS FundamentalsHardGATE CS · Amazon/Microsoft SDE MCQ

Table U(x INT UNIQUE) is empty. These statements run one at a time: INSERT (1); INSERT (NULL); INSERT (NULL); INSERT (1). How many succeed in standard SQL (as in SQLite and PostgreSQL by default)?

  1. A. 2
  2. B. 4
  3. C. 3
  4. D. 1

Correct answer: C. 3

UNIQUE rejects only equal non-NULL values, and NULLs are not considered equal to each other, so both NULLs are accepted and only the second 1 fails: 3. SQL Server is the well-known exception that allows a single NULL.

More DBMS and SQL questions

Exams that ask this topic