Hook: Interviewers like this question because it checks whether you understand how a table can identify one row without accidentally picking the wrong row later.
Question: What is a super key in SQL?
Answer: A super key is any set of one or more columns that can uniquely identify a row in a table. If a set works, then adding extra columns still keeps it a super key, even if those extra columns are not needed. A candidate key is the smallest possible super key, and the primary key is the one the database chooses as the main identifier.
Interview-Ready Answer: A super key is any column or combination of columns that uniquely identifies each row in a table. For example, if user_id is unique, then user_id is a super key, and user_id, email is also a super key because adding columns does not remove uniqueness. The important follow-up is that a candidate key is the minimal super key, and the primary key is the chosen candidate key that the database enforces most strongly.
Detailed Explanation: A super key is about uniqueness, not size. If a set of columns guarantees that no two rows share the same combined values, then that set is a super key. The set may be tiny, like one column, or larger, like a multi-column combination.
| Term | Meaning | Minimal? | SQL role |
|---|---|---|---|
| Super key | Any unique identifier set | No | Concept |
| Candidate key | Smallest super key | Yes | Possible key |
| Primary key | Chosen candidate key | Yes | Enforced main key |
You use super key thinking when you design tables and ask, What really identifies this row? In a school table, student_id may be enough. In a multi-tenant system, the pair tenant_id and order_no may be needed because the same order number can repeat in different tenants. This is why composite keys matter: sometimes one column is not enough.
In theory, keys are about relational design. In SQL, PRIMARY KEY means unique and not null, while UNIQUE means values must not repeat. However, many databases allow multiple NULL values in a UNIQUE column, so a nullable unique column is not always a practical row identifier. That is a common interview trap.
With a primary key or unique constraint, the database usually builds a B-tree index, which makes insert and lookup checks about O(log n) instead of O(n) table scans. On a million-row table, that usually means a small number of page reads rather than scanning every row. Without an index, proving uniqueness can become expensive very quickly.
Memory Hook: Think of a super key as a key ring: one working key is enough to open the door, and adding extra keys to the ring does not stop it from opening. The smallest key ring that still works is the candidate key.
Real-World Story: Imagine a multi-tenant checkout service for an online store. Each merchant has its own order_no, so order_no alone is not enough to identify an order across all merchants. The safe identifier is the combination tenant_id + order_no, which is a composite super key.
One day, a developer writes a join using only order_no. For merchant A and merchant B, both have order 1001, so the query matches two rows instead of one. The symptom is duplicate invoices, incorrect shipment status, and support tickets saying a customer saw another merchant’s order details. In logs, you may see ambiguous lookups, unexpected row counts, or application code failing with a message like more than one row returned.
The lesson is simple: a super key is not just academic language. It is the difference between a row being uniquely identifiable and a system quietly mixing up two customers.
-- Demonstration of a super key, a candidate key, and a practical edge case.
-- This script is intentionally simple and uses standard SQL that works in many databases.
DROP TABLE IF EXISTS users;
CREATE TABLE users (
user_id INTEGER PRIMARY KEY,
email VARCHAR(100) UNIQUE,
full_name VARCHAR(100) NOT NULL
);
INSERT INTO users (user_id, email, full_name) VALUES
(1, 'ava@example.com', 'Ava Patel'),
(2, NULL, 'Ben Lee'),
(3, NULL, 'Cara Gomez');
-- user_id alone uniquely identifies a row, so it is a super key.
SELECT user_id, email, full_name
FROM users
WHERE user_id = 2;
-- Adding extra columns does not hurt uniqueness, so this is also a super key.
SELECT user_id, email, full_name
FROM users
WHERE user_id = 2
AND full_name = 'Ben Lee';
-- Edge case: many databases allow multiple NULLs in a UNIQUE column.
-- That means a nullable UNIQUE column is not always a reliable identifier in practice.
SELECT user_id, email, full_name
FROM users
WHERE email IS NULL
ORDER BY user_id;Follow-up & Tricky Questions:
tenant_id plus order_no.UNIQUE always mean key? Not always in practice if the column allows NULL. Many SQL databases allow multiple NULLs in a unique column, so it may not identify every row cleanly.id is unique, is id, name also a super key? Yes, because uniqueness is preserved when you add more columns. It is just a non-minimal super key.NULL can make the column unsuitable as a real identifier.Common Mistakes:
id is unique, then id, anything is still unique.UNIQUE always means fully identifying: Check whether the column allows NULL, because that can change the practical meaning.Memory Hook: One working key on the ring is enough; the smallest working ring is the candidate key.
Cheat Sheet:
PRIMARY KEY implies unique and not null.UNIQUE with NULL can be a trap.Practice Tasks:
orders table.NULL values into a UNIQUE column and observe what your database allows.