1. Home
  2. Explore
  3. Computer Science
  4. Types of Database Keys

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Types of Database Keys

  • 27Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Foundational Key Concepts

Which property uniquely defines a primary key in a relational database?

27 questions

  1. 1

    Which property uniquely defines a primary key in a relational database?

    1. A

      It must be a natural key from the real world

    2. B

      It uniquely identifies each row and cannot contain null values

    3. C

      It can be changed to any value without affecting database integrity

    4. D

      It consists of a single attribute

    Correct answer
    B

    It 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.

  2. 2

    What is a candidate key?

    1. A

      Any attribute that uniquely identifies a row in the current data

    2. B

      A key that contains at least one foreign key attribute

    3. C

      A set of attributes that is irreducible and can uniquely identify rows

    4. D

      A foreign key that references another table's primary key

    Correct answer
    C

    A 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).

  3. 3

    Which statement about candidate keys is correct?

    1. A

      A table can have only one candidate key

    2. B

      Each candidate key must be irreducible and unique

    3. C

      All candidate keys are automatically enforced by the database

    4. D

      Candidate keys may contain null values if they are composite

    Correct answer
    B

    Each 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.

  4. 4

    How does a super key differ from a candidate key?

    1. A

      A super key is always a single attribute, while a candidate key can be composite

    2. B

      A super key is a foreign key that references another table

    3. C

      A super key contains all attributes of a candidate key plus possibly extra attributes

    4. D

      A super key cannot be used as a primary key, but a candidate key can

    Correct answer
    C

    A 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.

  5. 5

    What is an alternate key?

    1. A

      A foreign key that serves as an alternative to the primary key for joins

    2. B

      A key that can be null but remains unique

    3. C

      A surrogate key that replaces a natural key

    4. D

      A candidate key that is not chosen as the primary key and whose uniqueness is enforced via a constraint

    Correct answer
    D

    A 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.

  6. 6

    What is the primary purpose of a foreign key constraint?

    1. A

      To speed up query performance by creating an index

    2. B

      To ensure that values in a column match values in the primary key column of another table

    3. C

      To automatically generate unique values for new rows

    4. D

      To enforce uniqueness of values in a column within the same table

    Correct answer
    B

    To 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.

  7. 7

    Which of the following best describes a surrogate key?

    1. A

      An arbitrary, system-generated key with no intrinsic real-world meaning

    2. B

      A composite key made up of multiple foreign keys

    3. C

      A key derived from a natural identifier such as a social security number

    4. D

      A key whose values are meaningful to users outside the database

    Correct answer
    A

    An 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.

  8. 8

    What is a natural key?

    1. A

      A key that is used only for internal indexing and is hidden from users

    2. B

      A key that uses values that have real-world meaning, such as a state code

    3. C

      A key that is always composite and consists of multiple columns

    4. D

      A key that is generated automatically by the database system

    Correct answer
    B

    A 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.

  9. 9

    Which statement about surrogate keys is correct?

    1. A

      Surrogate keys are always composite keys

    2. B

      Surrogate keys guarantee that two rows never refer to the same real-world entity

    3. C

      Surrogate key values are arbitrary and could be changed consistently without breaking referential integrity

    4. D

      Surrogate key values must be derived from natural key values

    Correct answer
    C

    Surrogate 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.

  10. 10

    When would a database designer most likely choose a surrogate key over a natural key?

    1. A

      When the table has a composite primary key

    2. B

      When a reliable natural key exists and is stable

    3. C

      When the database requires all keys to be integers

    4. D

      When no obvious natural key exists or the natural key is unsuitable (e.g., may change or be null)

    Correct answer
    D

    When 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.

  11. 11

    What is a composite key?

    1. A

      A key that is composed of a single attribute

    2. B

      A key that is both a primary key and a foreign key

    3. C

      A key that includes only foreign key attributes

    4. D

      A key that consists of two or more attributes

    Correct answer
    D

    A 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).

  12. 12

    What distinguishes a compound key from a general composite key?

    1. A

      A compound key contains at least one attribute that is a foreign key

    2. B

      A compound key can have only two attributes

    3. C

      A compound key is a super key that includes extra attributes

    4. D

      A compound key is always a surrogate key

    Correct answer
    A

    A 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.

  13. 13

    What is a simple key?

    1. A

      A key that is automatically generated

    2. B

      A key that is easy to understand and remember

    3. C

      A key that does not contain foreign keys

    4. D

      A key that consists of a single attribute

    Correct answer
    D

    A 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.

  14. 14

    Which statement about the stability of a primary key is correct?

    1. A

      Stability requires the key to be a natural key

    2. B

      Stability is only required for foreign keys, not primary keys

    3. C

      Stability means the key values are unlikely to change over time

    4. D

      Stability is achieved by using a composite key

    Correct answer
    C

    Stability 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.

  15. 15

    What does it mean for a key to be irreducible?

    1. A

      It cannot contain foreign keys

    2. B

      It must be a simple key with one attribute

    3. C

      It cannot be split into smaller parts

    4. D

      It contains exactly the attributes needed for uniqueness; no extra attributes

    Correct answer
    D

    It 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.

  16. 16

    Why are primary key columns not allowed to contain null values?

    1. A

      Null values are allowed only in composite primary keys

    2. B

      Null is not a value and cannot serve to identify a row

    3. C

      Null values slow down query performance

    4. D

      Null values would make the column non-unique because nulls are distinct

    Correct answer
    B

    Null 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.

  17. 17

    Unique identification across time means that a candidate key must guarantee uniqueness:

    1. A

      Within the same database instance only

    2. B

      For all possible future rows as well

    3. C

      Across all tables in the schema

    4. D

      Only for the current set of rows in the table

    Correct answer
    B

    For 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.

  18. 18

    Why is including too many attributes in a primary key considered a mistake?

    1. A

      It allows duplicate rows to be inserted if the extra attribute varies

    2. B

      It prevents the use of foreign keys

    3. C

      It violates the rule that primary keys must be simple

    4. D

      It makes the key too long to index efficiently

    Correct answer
    A

    It 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.

  19. 19

    What does a foreign key constraint prevent?

    1. A

      Duplicate values in the foreign key column

    2. B

      Deletion of rows from the referenced table

    3. C

      Updating columns in the referencing table

    4. D

      Insertion of a value in the foreign key column that does not exist in the referenced primary key

    Correct answer
    D

    Insertion 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.

  20. 20

    In a join query using a foreign key, what condition is typically used?

    1. A

      The foreign key column is greater than the referenced column

    2. B

      The foreign key column equals the primary key column it references

    3. C

      The foreign key column contains unique values

    4. D

      Both tables have the same number of rows

    Correct answer
    B

    The 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.

  21. 21

    Which scenario correctly illustrates an intelligent key?

    1. A

      A product code like 'CLS-TRN-016' where each part has meaning (category, subcategory, sequence)

    2. B

      A foreign key that references the primary key of another table

    3. C

      A composite key consisting of two foreign keys

    4. D

      An auto-incrementing integer used as a primary key for customers

    Correct answer
    A

    A 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.

  22. 22

    What is a major pitfall of using intelligent keys?

    1. A

      They are always composite and hard to index

    2. B

      They require the database to support complex data types

    3. C

      They cannot be used as primary keys

    4. D

      People may rely on the embedded meanings, which can break if the key format changes

    Correct answer
    D

    People 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.

  23. 23

    When might an intelligent key be acceptable?

    1. A

      When the key is a single attribute

    2. B

      When the key is generated by a hash function

    3. C

      When the embedded meanings are essential for identification and unlikely to change

    4. D

      When the key is used only internally and not exposed to users

    Correct answer
    C

    When 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.

  24. 24

    In the context of the us states example, why is state code considered a better primary key than state name?

    1. A

      State code is a natural key while state name is a surrogate

    2. B

      State code cannot be changed

    3. C

      State name is not unique

    4. D

      State code is shorter and simpler

    Correct answer
    D

    State 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.

  25. 25

    Why is state capital not considered a candidate key for the us states table?

    1. A

      State capitals are not unique among current states

    2. B

      State capitals can change, and duplicates may occur in the future

    3. C

      State capital is a natural key

    4. D

      State capital is always null for some states

    Correct answer
    B

    State 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.

  26. 26

    What is an example of a compound key?

    1. A

      A single attribute that serves as both primary and foreign key

    2. B

      A key that includes a foreign key and a non-foreign attribute

    3. C

      A key that consists of three foreign keys

    4. D

      The primary key (customer_id, account_id) in a junction table where both attributes are foreign keys

    Correct answer
    D

    The 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.

  27. 27

    In the bookseller example, why is ISBN not used as the primary key for the books table?

    1. A

      ISBN is too long to be a primary key

    2. B

      ISBN is a surrogate key

    3. C

      Many ebooks do not have ISBNs, so it would not cover all books

    4. D

      ISBN numbers are not unique

    Correct answer
    C

    Many 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.

Question 1 of 27
Question 1 of 27

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent