Free Practice Quiz Question List

2 Keys and Relationships Online Quiz Questions

Use this free practice quiz with 20 questions to review 2 Keys and Relationships, test your knowledge, and prepare for your next test or exam.

20 questions
01
Choose one
1 point

An employee table has two columns, employee_id and work_email, each guaranteed to be unique. If employee_id is selected as the primary key, how should the database enforce uniqueness of work_email?

  1. A

    Declare both columns as primary keys.

  2. B

    Choose one column as the primary key and enforce uniqueness on the other.

  3. C

    Allow duplicates in the other column because the primary key is unique.

  4. D

    Make the other column a foreign key to the primary key.

02
Choose one
1 point

A shipment may be created before it is assigned to a warehouse. The shipment table stores the warehouse identifier in a foreign-key column. Which design allows a shipment to have no warehouse assignment yet?

  1. A

    Leave the foreign-key column nullable.

  2. B

    Add NOT NULL to the foreign-key column.

  3. C

    Add UNIQUE to the foreign-key column.

  4. D

    Make the foreign-key column a composite primary key.

03
Choose one
1 point

The registration table has a foreign key to the vehicle table. Which additional constraint prevents two registration rows from referring to the same vehicle?

  1. A

    Add CHECK to the foreign key.

  2. B

    Add NOT NULL to the foreign key.

  3. C

    Add UNIQUE to the foreign key.

  4. D

    Add a second foreign key to the same parent.

04
Choose all
1 point

Which two statements correctly describe a foreign key that references another table?

  1. A

    A non-null foreign-key value must match an existing referenced value.

  2. B

    A foreign key can refer to any column, even if that column is neither a primary key nor unique.

  3. C

    The referencing and referenced columns must correspond in number and have compatible data types.

  4. D

    A foreign key is valid only when it consists of a single column.

05
Written response
1 point

What SQL constraint would you add to a column when every row must contain a value in that column?

06
Fill in the blank
1 point

To require each row to satisfy a condition such as quantity > 0, use a constraint.

07
Written response
1 point

What is the database term for a minimal set of columns that uniquely identifies every row, such that removing any column would make it no longer unique?

08
Fill in the blank
1 point

A foreign key may be nullable when a relationship is optional. To require every row to be linked, add to the foreign-key column.

09
Choose all
1 point

A student can enroll in many courses, and a course can have many students. Which two design choices represent this relationship and prevent the same student-course pairing from being recorded twice?

  1. A

    Add a single nullable foreign key from students to courses.

  2. B

    Create an enrollments table with foreign keys to students and courses.

  3. C

    Give every course a UNIQUE student identifier.

  4. D

    Use the student and course identifiers together as the enrollments table's primary key.

10
Choose one
1 point

A training company needs to record which employees attend which workshops. Each employee may attend many workshops, and each workshop may have many employees. Which design best represents this relationship?

  1. A

    Store every workshop identifier in a single column of each employee row.

  2. B

    Create a junction table with foreign keys to both employees and workshops.

  3. C

    Make each workshop identifier a foreign key to an employee identifier.

  4. D

    Put all employee identifiers into a single column of each workshop row.

11
Open ended
1 point

A library is adding a loans table that refers to members. Explain how to define the foreign-key relationship so that every loan must refer to an existing member, and state the column requirements for the reference.

12
Choose one
1 point

An employee table guarantees that employee_id and work_email are each unique and non-null. Which statement about candidate keys is correct?

  1. A

    Both employee_id and work_email are candidate keys.

  2. B

    employee_id is a candidate key, but work_email cannot be one because it is an email address.

  3. C

    Only work_email is a candidate key because it is unique.

  4. D

    Neither is a candidate key unless both columns are combined.

13
True or false
1 point

A nullable foreign key can represent an optional relationship, while every non-null foreign-key value must match an existing referenced value.

  1. A

    True

  2. B

    False

14
Choose one
1 point

A table uses (region_code, account_no) together as its main identifier. Which statement correctly describes this design?

  1. A

    The table cannot use the pair as its primary key because a primary key must be one column.

  2. B

    The table can use the pair as one composite primary key.

  3. C

    The table must declare each column as a separate primary key.

  4. D

    The table can use the pair only if neither column is unique by itself.

15
Choose one
1 point

An order must always belong to a customer. Its customer_id column references customers.customer_id, but the foreign-key column is currently nullable. Which change enforces the requirement that every order be linked?

  1. A

    Add UNIQUE to customer_id so every order points to a customer.

  2. B

    Add CHECK (customer_id > 0) so every order points to a customer.

  3. C

    Add NOT NULL to customer_id so every order must be linked.

  4. D

    No additional rule is needed because a foreign key cannot be null.

16
Written response
1 point

In an employee table, employee_id is the primary key and work_email is another candidate key. Which SQL constraint keyword can enforce uniqueness of work_email?

17
Choose one
1 point

A design requires that no two profile rows refer to the same user row. Which constraint on the profile table's foreign key enforces this one-to-one relationship?

  1. A

    Add a UNIQUE constraint to the foreign-key column.

  2. B

    Allow the foreign-key column to be nullable.

  3. C

    Use the foreign key as part of a junction table.

  4. D

    Add a CHECK constraint requiring the foreign key to be positive.

18
True or false
1 point

An orders table uses a foreign key to reference customers, and the foreign key is configured with ON DELETE CASCADE. If a referenced customer is deleted, dependent order rows are deleted as well. True or false?

  1. A

    True

  2. B

    False

19
True or false
1 point

Once a row has been inserted, database constraints no longer apply when that row is changed. True or false?

  1. A

    True

  2. B

    False

20
Written response
1 point

A customer row is referenced by existing orders. The system must block deletion of that customer while those references remain. Which referential action should be used?