Types of Database Keys
- 21Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
- spaceFlip card
- KI knew it
- DI didn't know it
- âPrevious card
- âNext card
What is a primary key in a relational database?
A primary key is a column or set of columns that uniquely identifies each row in a table. It must contain unique values and cannot contain NULL.
Or swipe the card
21 cards
What is a primary key in a relational database?
A primary key is a column or set of columns that uniquely identifies each row in a table. It must contain unique values and cannot contain NULL.
What does 'stability' mean for an identifier?
Stability means the identifier's values are not likely to change over time. For example, state codes are stable, but mobile phone numbers are not because people change them.
What is a candidate key?
A candidate key is a column or set of columns that could serve as the primary key because it uniquely identifies each row and is irreducible (contains only necessary attributes).
What is a super key?
A super key is a set of attributes that contains a candidate key, potentially with additional attributes. It uniquely identifies rows but may have extra columns.
What is an alternate key?
An alternate key is a candidate key that is not chosen as the primary key. The database must enforce uniqueness on alternate keys explicitly.
What is a foreign key?
A foreign key is a column or set of columns in one table that references the primary key (or a unique key) of another table. It ensures referential integrity by restricting values to those existing in the referenced table.
What is a surrogate key?
A surrogate key is an artificial key that has no inherent real-world meaning. Its values are only meaningful within the database context (e.g., an auto-incrementing integer).
What is a natural key?
A natural key (or business key) is a key that has real-world meaning and is naturally associated with the entity (e.g., state code 'GA', Social Security Number).
What is a simple key?
A simple key is a key consisting of a single attribute (column).
What is a composite key?
A composite key is a key consisting of two or more attributes. For example, (coffee_type, cup_size) uniquely identifies a coffee option.
What is a compound key?
A compound key is a composite key where at least one attribute is a foreign key to another table. Some use the term interchangeably with composite key.
What is an intelligent key?
An intelligent key is a natural key made up of multiple parts, each with its own meaning. For example, product code 'CLS-TRN-016' where 'CLS' means classic and 'TRN' means train set.
When should you use a surrogate key instead of a natural key?
Use a surrogate key when no suitable natural key exists (e.g., for recipes), or when the natural key is unstable, too long, or has scope limitations (e.g., ISBN doesn't cover ebooks).
Why is it important that a candidate key is irreducible?
Irreducibility means no attributes can be removed without losing uniqueness. A key that includes extra attributes is a super key, not a candidate key, and can allow duplicate rows.
What does 'uniqueness across time' mean for candidate keys?
A candidate key must guarantee uniqueness not only for current data but also for any possible future data. Just because values are currently unique doesn't make it a candidate key if duplicates could occur later.
What are the pitfalls of intelligent keys?
- People may rely on parsing the key for meaning (e.g., extracting product subcategory), which breaks if key format changes. 2. Category changes can conflict with key structure (e.g., from 'classic/modern' to 'battery/non-battery').
What happens if a surrogate key is not properly constrained?
Without a unique constraint on natural attributes, duplicate rows for the same real-world entity can appear. For example, two rows for 'Massachusetts' with different surrogate IDs but same state code.
How does a foreign key constraint enforce referential integrity?
It ensures that every value in the foreign key column matches a value in the referenced primary key (or unique) column. This prevents orphan records and maintains consistency between tables.
If a composite primary key is used, how does it affect foreign keys?
A foreign key referencing a composite primary key must also be composite, with the same number and order of columns. For example, referencing (coffee_type, cup_size) requires foreign key (coffee_type, cup_size).
What is the difference between a surrogate key and a natural key in terms of real-world meaning?
A natural key has inherent real-world meaning (e.g., state code 'GA'), while a surrogate key's meaning is confined to the database (e.g., auto-increment ID 25). People outside the database may not know the surrogate's mapping.
Can a column be both a primary key and a foreign key?
Yes, a column can be part of a composite primary key and also be a foreign key. For example, in a junction table, (customer_id, account_id) is the primary key, and both are foreign keys to their respective tables.

Ask anything
We've read this whole study set, so questions about it get the best answers.