Tables, Keys & Constraints · Question 8 · Medium

In PostgreSQL, MySQL and SQLite, which follow the SQL standard on this point, what does the final SELECT return?

CREATE TABLE Users (
  id INT PRIMARY KEY,
  email VARCHAR(40) UNIQUE
);
INSERT INTO Users VALUES (1, NULL);
INSERT INTO Users VALUES (2, NULL);
INSERT INTO Users VALUES (3, '[email protected]');
SELECT COUNT(*) FROM Users;
  1. 2
  2. 1
  3. 3
  4. Nothing: the second INSERT fails with a UNIQUE violation
Answer and explanation

Answer: C. 3

Explanation: UNIQUE forbids two equal non-NULL values. NULL is not considered equal to another NULL, so these engines accept any number of NULLs in a UNIQUE column, and all three rows are stored. (SQL Server is the well-known exception: it allows only one NULL.)

Previous: What happens when the INSERT with a price of -50 runs? · Next: Table Member: id | name 1 | Asha 2 | Bala The table Member below already has…

Practise tables, keys & constraints

Try a fresh set of tables, keys & constraints questions with an explanation after every answer, free and without signing up: Tables, Keys & Constraints practice. Or sit a full placement mock test.

More tables, keys & constraints questions

More sql practice

DML & Transactions · SELECT, WHERE & ORDER BY · SQL Joins · Aggregates & GROUP BY · Subqueries & CTEs · Window Functions · NULL Handling · SQL Functions & CASE

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge