What are super, candidate, primary, alternate and composite keys?
EasyConceptKeys & Constraints
Answer
A key is a set of one or more columns used to identify rows in a table. The different names describe how minimal the set is and how it is used.
- Super key: any set of columns whose values are unique for every row.
- Candidate key: a minimal super key; removing any column from it breaks uniqueness.
- Primary key: the candidate key chosen as the main identifier; it can never be
NULL. The remaining candidate keys are alternate keys. - Composite key: a key made of two or more columns.
Example: students(roll, email, name)
roll | email | name
1 | a@clg.edu | Asha
2 | r@clg.edu | Ravi
3 | k@clg.edu | Asha
- Super keys include
{roll},{email},{roll, name}and{roll, email};{name}alone is not one, because Asha repeats. - Candidate keys:
{roll}and{email};{roll, name}is not minimal. - Primary key:
{roll}; alternate key:{email}. - In
enrolments(roll, course_id), the composite key is(roll, course_id).
More in Keys & Constraints
| # | Problem | Platform | Difficulty | Open | 1st1st Visit | 2nd2nd Visit | RevRevise |
|---|---|---|---|---|---|---|---|
| 1 | What are super, candidate, primary, alternate and composite keys? | Concept | Easy | Read the answer to What are super, candidate, primary, alternate and composite keys? | |||
| 2 | What is the difference between a primary key and a unique key? | Concept | Easy | Read the answer to What is the difference between a primary key and a unique key? | |||
| 3 | What are integrity constraints in DBMS? | Concept | Easy | Read the answer to What are integrity constraints in DBMS? | |||
| 4 | What is a foreign key, and what do ON DELETE CASCADE and ON DELETE SET NULL do? | Concept | Medium | Read the answer to What is a foreign key, and what do ON DELETE CASCADE and ON DELETE SET NULL do? |