Types of Database Keys
- 27Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
Which property uniquely defines a primary key in a relational database?
Which property uniquely defines a primary key in a relational database?
27 questions
- 1
Which property uniquely defines a primary key in a relational database?
- A
It must be a natural key from the real world
- B
It uniquely identifies each row and cannot contain null values
- C
It can be changed to any value without affecting database integrity
- D
It consists of a single attribute
Correct answer
BIt uniquely identifies each row and cannot contain null values
Explanation
A primary key uniquely identifies each row in a table and the database platform enforces uniqueness and prohibits null values in the primary key columns.
- A
- 2
What is a candidate key?
- A
Any attribute that uniquely identifies a row in the current data
- B
A key that contains at least one foreign key attribute
- C
A set of attributes that is irreducible and can uniquely identify rows
- D
A foreign key that references another table's primary key
Correct answer
CA set of attributes that is irreducible and can uniquely identify rows
Explanation
A candidate key is an attribute or combination of attributes that can serve as a primary key; it is unique and irreducible (no unnecessary attributes).
- A
- 3
Which statement about candidate keys is correct?
- A
A table can have only one candidate key
- B
Each candidate key must be irreducible and unique
- C
All candidate keys are automatically enforced by the database
- D
Candidate keys may contain null values if they are composite
Correct answer
BEach candidate key must be irreducible and unique
Explanation
A candidate key must be unique and irreducible (no subset of its attributes also uniquely identifies rows). It may or may not be chosen as the primary key.
- A
- 4
How does a super key differ from a candidate key?
- A
A super key is always a single attribute, while a candidate key can be composite
- B
A super key is a foreign key that references another table
- C
A super key contains all attributes of a candidate key plus possibly extra attributes
- D
A super key cannot be used as a primary key, but a candidate key can
Correct answer
CA super key contains all attributes of a candidate key plus possibly extra attributes
Explanation
A super key is any set of attributes that contains a candidate key; it may have additional attributes beyond those needed for uniqueness.
- A
- 5
What is an alternate key?
- A
A foreign key that serves as an alternative to the primary key for joins
- B
A key that can be null but remains unique
- C
A surrogate key that replaces a natural key
- D
A candidate key that is not chosen as the primary key and whose uniqueness is enforced via a constraint
Correct answer
DA candidate key that is not chosen as the primary key and whose uniqueness is enforced via a constraint
Explanation
An alternate key is a candidate key that was not selected as the primary key; its uniqueness must be explicitly enforced with a unique constraint.
- A
- 6
What is the primary purpose of a foreign key constraint?
- A
To speed up query performance by creating an index
- B
To ensure that values in a column match values in the primary key column of another table
- C
To automatically generate unique values for new rows
- D
To enforce uniqueness of values in a column within the same table
Correct answer
BTo ensure that values in a column match values in the primary key column of another table
Explanation
A foreign key constraint ensures referential integrity by requiring that every value in the foreign key column exists in the referenced primary key column of another table.
- A
- 7
Which of the following best describes a surrogate key?
- A
An arbitrary, system-generated key with no intrinsic real-world meaning
- B
A composite key made up of multiple foreign keys
- C
A key derived from a natural identifier such as a social security number
- D
A key whose values are meaningful to users outside the database
Correct answer
AAn arbitrary, system-generated key with no intrinsic real-world meaning
Explanation
A surrogate key is an artificial key (often an auto-incrementing number) whose values have no real-world significance outside the database.
- A
- 8
What is a natural key?
- A
A key that is used only for internal indexing and is hidden from users
- B
A key that uses values that have real-world meaning, such as a state code
- C
A key that is always composite and consists of multiple columns
- D
A key that is generated automatically by the database system
Correct answer
BA key that uses values that have real-world meaning, such as a state code
Explanation
A natural key is an identifier that exists in the real world and has meaning to users, like a postal abbreviation, email address, or national ID number.
- A
- 9
Which statement about surrogate keys is correct?
- A
Surrogate keys are always composite keys
- B
Surrogate keys guarantee that two rows never refer to the same real-world entity
- C
Surrogate key values are arbitrary and could be changed consistently without breaking referential integrity
- D
Surrogate key values must be derived from natural key values
Correct answer
CSurrogate key values are arbitrary and could be changed consistently without breaking referential integrity
Explanation
Surrogate key values are arbitrary; if they are changed consistently (e.g., all references updated), the database remains consistent. However, without an alternate key, they do not guarantee uniqueness of real-world entities.
- A
- 10
When would a database designer most likely choose a surrogate key over a natural key?
- A
When the table has a composite primary key
- B
When a reliable natural key exists and is stable
- C
When the database requires all keys to be integers
- D
When no obvious natural key exists or the natural key is unsuitable (e.g., may change or be null)
Correct answer
DWhen no obvious natural key exists or the natural key is unsuitable (e.g., may change or be null)
Explanation
Surrogate keys are often used when no suitable natural key is available, such as for recipes where no stable unique identifier exists, or when natural keys like ISBNs are not universal.
- A
- 11
What is a composite key?
- A
A key that is composed of a single attribute
- B
A key that is both a primary key and a foreign key
- C
A key that includes only foreign key attributes
- D
A key that consists of two or more attributes
Correct answer
DA key that consists of two or more attributes
Explanation
A composite key is a key made up of more than one attribute, such as (coffee_type, cup_size).
- A
- 12
What distinguishes a compound key from a general composite key?
- A
A compound key contains at least one attribute that is a foreign key
- B
A compound key can have only two attributes
- C
A compound key is a super key that includes extra attributes
- D
A compound key is always a surrogate key
Correct answer
AA compound key contains at least one attribute that is a foreign key
Explanation
A compound key is a composite key in which at least one of the attributes is a foreign key referencing another table. An example is a junction table's primary key made of two foreign keys.
- A
- 13
What is a simple key?
- A
A key that is automatically generated
- B
A key that is easy to understand and remember
- C
A key that does not contain foreign keys
- D
A key that consists of a single attribute
Correct answer
DA key that consists of a single attribute
Explanation
A simple key is a key that consists of only one column, as opposed to a composite key which has multiple columns.
- A
- 14
Which statement about the stability of a primary key is correct?
- A
Stability requires the key to be a natural key
- B
Stability is only required for foreign keys, not primary keys
- C
Stability means the key values are unlikely to change over time
- D
Stability is achieved by using a composite key
Correct answer
CStability means the key values are unlikely to change over time
Explanation
A stable identifier is one whose values are not likely to change. For example, state postal codes are stable, while mobile phone numbers are not.
- A
- 15
What does it mean for a key to be irreducible?
- A
It cannot contain foreign keys
- B
It must be a simple key with one attribute
- C
It cannot be split into smaller parts
- D
It contains exactly the attributes needed for uniqueness; no extra attributes
Correct answer
DIt contains exactly the attributes needed for uniqueness; no extra attributes
Explanation
Irreducibility means that if you remove any attribute from the key, it would no longer uniquely identify rows. A candidate key is irreducible; a super key is not.
- A
- 16
Why are primary key columns not allowed to contain null values?
- A
Null values are allowed only in composite primary keys
- B
Null is not a value and cannot serve to identify a row
- C
Null values slow down query performance
- D
Null values would make the column non-unique because nulls are distinct
Correct answer
BNull is not a value and cannot serve to identify a row
Explanation
To identify a row, an actual value is needed; null is the absence of a value and therefore cannot be part of a primary key.
- A
- 17
Unique identification across time means that a candidate key must guarantee uniqueness:
- A
Within the same database instance only
- B
For all possible future rows as well
- C
Across all tables in the schema
- D
Only for the current set of rows in the table
Correct answer
BFor all possible future rows as well
Explanation
A key must ensure that no two rows will ever share the same key value, even if new rows are added in the future. For example, state capital is not a candidate key because capitals can change and duplicates could occur.
- A
- 18
Why is including too many attributes in a primary key considered a mistake?
- A
It allows duplicate rows to be inserted if the extra attribute varies
- B
It prevents the use of foreign keys
- C
It violates the rule that primary keys must be simple
- D
It makes the key too long to index efficiently
Correct answer
AIt allows duplicate rows to be inserted if the extra attribute varies
Explanation
If a primary key includes an unnecessary attribute, it no longer uniquely identifies rows in an irreducible way, allowing duplicates that differ only in that extra attribute, leading to incorrect data.
- A
- 19
What does a foreign key constraint prevent?
- A
Duplicate values in the foreign key column
- B
Deletion of rows from the referenced table
- C
Updating columns in the referencing table
- D
Insertion of a value in the foreign key column that does not exist in the referenced primary key
Correct answer
DInsertion of a value in the foreign key column that does not exist in the referenced primary key
Explanation
A foreign key constraint ensures that every value in the foreign key column matches a value in the primary key column it references, preventing orphaned records.
- A
- 20
In a join query using a foreign key, what condition is typically used?
- A
The foreign key column is greater than the referenced column
- B
The foreign key column equals the primary key column it references
- C
The foreign key column contains unique values
- D
Both tables have the same number of rows
Correct answer
BThe foreign key column equals the primary key column it references
Explanation
A join using a foreign key matches each value in the foreign key column to the corresponding value in the referenced primary key column.
- A
- 21
Which scenario correctly illustrates an intelligent key?
- A
A product code like 'CLS-TRN-016' where each part has meaning (category, subcategory, sequence)
- B
A foreign key that references the primary key of another table
- C
A composite key consisting of two foreign keys
- D
An auto-incrementing integer used as a primary key for customers
Correct answer
AA product code like 'CLS-TRN-016' where each part has meaning (category, subcategory, sequence)
Explanation
An intelligent key is a natural key composed of multiple meaningful parts, such as product codes that encode category, subcategory, and sequence number.
- A
- 22
What is a major pitfall of using intelligent keys?
- A
They are always composite and hard to index
- B
They require the database to support complex data types
- C
They cannot be used as primary keys
- D
People may rely on the embedded meanings, which can break if the key format changes
Correct answer
DPeople may rely on the embedded meanings, which can break if the key format changes
Explanation
Because intelligent keys have built-in meanings, others might parse those meanings (e.g., to group sales by subcategory). If the key format changes, such dependencies break.
- A
- 23
When might an intelligent key be acceptable?
- A
When the key is a single attribute
- B
When the key is generated by a hash function
- C
When the embedded meanings are essential for identification and unlikely to change
- D
When the key is used only internally and not exposed to users
Correct answer
CWhen the embedded meanings are essential for identification and unlikely to change
Explanation
Intelligent keys work best when the parts that make up the key are essential to the identity and are stable, such as a customer ID composed of date of birth and sequence number.
- A
- 24
In the context of the us states example, why is state code considered a better primary key than state name?
- A
State code is a natural key while state name is a surrogate
- B
State code cannot be changed
- C
State name is not unique
- D
State code is shorter and simpler
Correct answer
DState code is shorter and simpler
Explanation
Although both are candidate keys, state code (e.g., 'TX') is simpler and shorter than the full state name, making it a more practical primary key.
- A
- 25
Why is state capital not considered a candidate key for the us states table?
- A
State capitals are not unique among current states
- B
State capitals can change, and duplicates may occur in the future
- C
State capital is a natural key
- D
State capital is always null for some states
Correct answer
BState capitals can change, and duplicates may occur in the future
Explanation
State capitals are not guaranteed to be unique across time; a state could change its capital to one already used by another state, violating uniqueness.
- A
- 26
What is an example of a compound key?
- A
A single attribute that serves as both primary and foreign key
- B
A key that includes a foreign key and a non-foreign attribute
- C
A key that consists of three foreign keys
- D
The primary key (customer_id, account_id) in a junction table where both attributes are foreign keys
Correct answer
DThe primary key (customer_id, account_id) in a junction table where both attributes are foreign keys
Explanation
A compound key is a composite key where at least one attribute is a foreign key. The junction table's primary key (customer_id, account_id) fits this definition.
- A
- 27
In the bookseller example, why is ISBN not used as the primary key for the books table?
- A
ISBN is too long to be a primary key
- B
ISBN is a surrogate key
- C
Many ebooks do not have ISBNs, so it would not cover all books
- D
ISBN numbers are not unique
Correct answer
CMany ebooks do not have ISBNs, so it would not cover all books
Explanation
ISBNs are not assigned to all ebooks, so using ISBN as the primary key would leave ebooks without a key. A surrogate book number is used instead.
- A

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