Types of Database Keys
- 37Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
Define stability of an identifier and give an example of a stable versus unstable identifier.
37 questions
- 1
Define stability of an identifier and give an example of a stable versus unstable identifier.
Model answer
Stability means an identifier's values are unlikely to change their meaning over time. A stable identifier is U.S. state postal code (e.g., MA always means Massachusetts); an unstable identifier is a mobile phone number, which people often change.
Explanation
The video contrasts state code (stable) with mobile phone number (unstable) to illustrate that stable identifiers are preferred for keys.
- 2
Why can't a primary key contain null values?
Model answer
Null is not a value; it represents the absence of a value. Since a primary key must uniquely identify each row, it cannot contain nulls because null cannot serve as an identifying value.
Explanation
The video states that database platforms do not permit nullable attributes in primary keys because null isn't a value that can identify anything.
- 3
What is an irreducible key?
Model answer
An irreducible key is a key that contains only the attributes necessary to ensure uniqueness, with no extra attributes beyond those required.
Explanation
The video explains that a key is irreducible if it has only the attributes needed for uniqueness; having extra attributes makes it a super key, not a candidate key.
- 4
What is a super key? How does it differ from a candidate key?
Model answer
A super key is a set of attributes that contains a candidate key as a subset, possibly with additional attributes. A candidate key is an irreducible super key (no unnecessary attributes).
Explanation
The video uses the example of (state_code, region) as a super key because it includes the candidate key state_code plus the extra attribute region.
- 5
What is the relationship between a super key, candidate key, and primary key?
Model answer
A primary key is one chosen candidate key. Every candidate key is an irreducible super key. All candidate keys are super keys, but not all super keys are candidate keys (because they may have extra attributes).
Explanation
The video defines these terms hierarchically: super keys contain candidate keys, and one candidate key becomes the primary key.
- 6
Why is irreducibility important for a candidate key?
Model answer
Irreducibility ensures that the key has no redundant attributes; if extra attributes were included, the key could allow duplicate rows for the same real-world entity, as shown when (state_code, region) allowed duplicate states.
Explanation
The video shows that using (state_code, region) as primary key allowed two rows for Georgia because region was unnecessary for uniqueness.
- 7
What is a candidate key? Give an example from the US states table.
Model answer
A candidate key is a minimal set of attributes that uniquely identifies each row. In the US states table, both state_code and state_name are candidate keys because each uniquely identifies a state.
Explanation
The video explains that candidate keys are the options considered for the primary key; state_code and state_name are unique identifiers.
- 8
Why is state_code considered a candidate key for the US states table?
Model answer
Each U.S. state has a unique official postal abbreviation that is stable and never changes, so state_code uniquely identifies a state now and in the future.
Explanation
The video emphasizes that state_code is a stable, unique identifier for each state.
- 9
Why is state_capital not considered a candidate key for the US states table?
Model answer
State capitals are not guaranteed to be unique across time; a state could change its capital to a name already used by another state, making it possible for two states to share the same capital name in the future.
Explanation
The video uses historical and hypothetical examples (Georgia changing capital to Augusta) to show that state capital names are not guaranteed unique over time.
- 10
Explain the principle that unique identification must hold across time.
Model answer
An identifier must uniquely identify entities not only in the current data but also in all possible future instances. If there is any chance that two entities could share the same identifier value in the future, it is not a key.
Explanation
The video stresses that candidate keys must guarantee uniqueness for all possible future states, not just the present set of rows.
- 11
What is the primary key? Why was state_code chosen over state_name in the example?
Model answer
The primary key is the candidate key selected as the main unique identifier for the table. State_code was chosen over state_name purely for simplicity (two-letter abbreviation is shorter).
Explanation
The video says either could work but state_code is simpler.
- 12
What happens if you try to insert a duplicate primary key value?
Model answer
The database will reject the insert and raise an error, because the primary key constraint enforces uniqueness.
Explanation
The video uses the example of trying to insert another row with state_code 'TX' after one already exists.
- 13
In the US states example, what would be the consequence of setting the primary key as (state_code, region)? Why is this problematic?
Model answer
It would allow duplicate states (e.g., two rows for Georgia) because state_code alone is sufficient for uniqueness; the extra attribute region makes the key non-irreducible and allows incorrect duplicates.
Explanation
The video shows that with (state_code, region) as primary key, two Georgia rows can exist because they differ in region, which is not needed to uniquely identify the state.
- 14
What is an alternate key? Give an example using the US states table.
Model answer
An alternate key is a candidate key that is not chosen as the primary key. In the US states table, if state_code is the primary key, then state_name is an alternate key.
Explanation
The video explicitly calls state_name an alternate key after state_code is designated as primary key.
- 15
Why is it necessary to enforce uniqueness of an alternate key separately?
Model answer
The database does not automatically enforce uniqueness for candidate keys other than the primary key; you must add a unique constraint on the alternate key to prevent duplicate values.
Explanation
The video shows that without an explicit alternate key constraint, state_name could have duplicates, so you must use a UNIQUE constraint on state_name.
- 16
What is a foreign key constraint? How does it ensure referential integrity?
Model answer
A foreign key constraint specifies that values in a column (or columns) must match values in the primary key (or unique key) of another table. It prevents orphaned references and ensures data consistency across tables.
Explanation
The video uses the voters table example: setting state_of_voter_registration as a foreign key to state_code ensures that only valid state codes are used.
- 17
Write a SQL-like example of a foreign key definition for the voters table referencing state_code.
Model answer
FOREIGN KEY (state_of_voter_registration) REFERENCES us_states(state_code)
Explanation
The video describes this constraint as telling the database that every value in state_of_voter_registration must match a state_code in us_states.
- 18
What problem arises if a foreign key column contains a value not present in the referenced primary key column? How does a foreign key constraint prevent this?
Model answer
Such a value would create an orphan record that cannot be linked to any parent row. A foreign key constraint rejects any insert or update that would produce such an unmatched value.
Explanation
The video mentions that 'QX' would not be allowed because it does not exist in the us_states table; the constraint enforces this.
- 19
Define a natural key. Give two examples from real life.
Model answer
A natural key is an identifier that has real-world meaning and is used outside the database. Examples: U.S. state postal code (GA), Social Security number, email address, customer number on a letter.
Explanation
The video lists multiple natural keys: state code, national ID, email, customer number.
- 20
Define a surrogate key. How does its meaning differ from a natural key?
Model answer
A surrogate key is an artificial identifier with no inherent real-world meaning; its values only have meaning within the database. In contrast, a natural key has meaning outside the database (e.g., GA stands for Georgia in the real world).
Explanation
The video explains that state_id (25) only means Georgia in the database context, whereas GA is a real-world abbreviation.
- 21
In the alternative design using state_id, why is state_id a surrogate key?
Model answer
state_id is a surrogate key because it is an arbitrary number assigned by the database that has no real-world meaning; it only identifies the state within the database.
Explanation
The video calls state_id a surrogate key because it is a stand-in for the real entity, with no external significance.
- 22
What is the key difference between state_code and state_id in terms of real-world meaning?
Model answer
state_code (e.g., GA) is widely recognized outside the database as an abbreviation for Georgia; state_id (e.g., 25) has no such external meaning and only identifies Georgia within the database.
Explanation
The video emphasizes that many people know GA as shorthand for Georgia, but no one associates 25 with Georgia outside the database.
- 23
Explain the pitfall of using a surrogate key as merely a row identifier. What problem could occur?
Model answer
If a surrogate key is treated only as a row ID, it is possible to insert multiple rows with different surrogate IDs that refer to the same real-world entity (e.g., two rows both representing Massachusetts but with different state_ids).
Explanation
The video shows an example where two rows with different state_ids both describe Massachusetts, which is incorrect because each state should appear only once.
- 24
What should be done to ensure that a surrogate key correctly identifies real-world entities?
Model answer
Either create an alternate key (like state_code) to enforce uniqueness of the real-world entity, or ensure the data insertion process prevents multiple rows for the same entity.
Explanation
The video proposes using state_code as an alternate key to guarantee that no two surrogate IDs refer to the same state, or careful application logic.
- 25
When would you choose a natural key as the primary key? When would you choose a surrogate key?
Model answer
Use a natural key when a stable, unique real-world identifier exists (e.g., U.S. state code). Use a surrogate key when no suitable natural key exists (e.g., recipes) or when the natural key has limitations (e.g., ISBN not available for ebooks).
Explanation
The video discusses the decision using recipes (no natural key -> surrogate) and online bookseller (ISBN unsuitable -> surrogate book number).
- 26
In the online bookseller example, why is ISBN not suitable as a primary key? How is the issue resolved?
Model answer
ISBN is not suitable because many ebooks do not have an ISBN. The solution is to invent an internal book number that applies to both print and ebooks, making it the primary key; ISBN remains as an attribute but not the primary key.
Explanation
The video explains that if the books table includes ebooks, ISBN cannot be a primary key because it is not present for all rows.
- 27
What is a simple key? Give an example.
Model answer
A simple key is a key that consists of a single attribute. Example: state_code alone as the primary key of the US states table.
Explanation
The video defines simple key as a key with just one column, contrasting with composite keys.
- 28
What is a composite key? Give an example from the coffee options table.
Model answer
A composite key is a key that consists of more than one attribute. Example: (coffee_type, cup_size) as the primary key for the coffee options table, because a coffee option is uniquely identified by the combination of type and size.
Explanation
The video uses the coffee table to illustrate a composite primary key.
- 29
When a composite primary key is used, how is a foreign key defined?
Model answer
A foreign key referencing a composite primary key must itself be composite, with the same number of attributes and compatible data types, matching the referenced columns in order.
Explanation
The video shows that for the preferred coffee table, the foreign key (coffee_type_of_preferred_option, cup_size_of_preferred_option) references (coffee_type, cup_size).
- 30
What is a compound key according to some database terminology? Give an example.
Model answer
A compound key is a composite key where at least one attribute is also a foreign key. Example: in a customer_account table, the primary key (customer_id, account_id) is a compound key because both attributes are foreign keys to their respective tables.
Explanation
The video notes that some people use compound key specifically for composite keys that include foreign keys.
- 31
How does a compound key differ from a general composite key?
Model answer
All compound keys are composite keys, but not all composite keys are compound keys. A compound key is a composite key that contains at least one attribute that is a foreign key. A general composite key may have no foreign key components (e.g., (coffee_type, cup_size) with no foreign keys).
Explanation
The video distinguishes that (coffee_type, cup_size) is a composite key but not a compound key because neither attribute is a foreign key.
- 32
In the customer-account example, why is the primary key of the junction table a compound key?
Model answer
Because the primary key consists of two attributes, each of which is a foreign key: customer_id references the customer table, and account_id references the account table.
Explanation
The video explicitly states that customer_id and account_id are both foreign keys, making the primary key a compound key.
- 33
What is an intelligent key? Give an example from the toy company product codes.
Model answer
An intelligent key is a natural key composed of multiple meaningful parts concatenated together. Example: product code 'CLS_TRN_016' where 'CLS' means classic, 'TRN' means train set, and '016' is a sequence number.
Explanation
The video defines intelligent keys and provides the toy product code structure.
- 34
What are the components of the product code in the toy example? What does each part signify?
Model answer
The product code has three parts: product category (e.g., 'CLS' for classic, 'MOD' for modern), product subcategory (e.g., 'JIG' for jigsaw, 'QCP' for quadcopter), and a sequence number unique within the subcategory.
Explanation
The video describes the three-part structure and their meanings.
- 35
Why is it risky to extract meaning from parts of an intelligent key?
Model answer
If people rely on extracting subcategory from the key (e.g., parsing 'JIG' from the middle), that assumption will break if the company changes the key format, leading to incorrect reports or application failures.
Explanation
The video warns that reports extracting subcategory from product code will stop working if the encoding changes.
- 36
What problems can occur when the classification scheme behind an intelligent key changes?
Model answer
The key may no longer match the new categories (e.g., switching from classic/modern to battery-operated/non-battery-operated), causing confusion or requiring large-scale updates to existing keys.
Explanation
The video discusses the conflict if the company changes its product categorization scheme.
- 37
Under what conditions can an intelligent key be relatively safe? Give an example.
Model answer
An intelligent key is relatively safe when its components are essential and stable. Example: a customer identifier composed of date of birth and a sequence number (e.g., 1997.0308.0096) because date of birth never changes.
Explanation
The video suggests that stable components like date of birth make the key less problematic.

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