Bird
Raised Fist0
DBMS Theoryknowledge~20 mins

Keys (primary, candidate, foreign, super) in DBMS Theory - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Key Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Primary Keys

Which of the following best describes the role of a primary key in a database table?

AIt uniquely identifies each record and cannot contain NULL values.
BIt is a key that can have duplicate values and may contain NULLs.
CIt is used to link two tables but does not uniquely identify records.
DIt is any attribute that can be used to identify records but is not necessarily unique.
Attempts:
2 left
💡 Hint

Think about what makes each row in a table unique and mandatory.

📋 Factual
intermediate
2:00remaining
Candidate Keys Characteristics

Which statement correctly defines a candidate key?

AA candidate key is a key that is chosen as the primary key.
BA candidate key is a key that can contain duplicate values.
CA candidate key is a key that references another table's primary key.
DA candidate key is any attribute or set of attributes that can uniquely identify a record.
Attempts:
2 left
💡 Hint

Think about keys that could potentially be primary keys.

🔍 Analysis
advanced
2:00remaining
Foreign Key Purpose

What is the main purpose of a foreign key in a relational database?

ATo serve as an alternate unique identifier within the same table.
BTo enforce referential integrity by linking to a primary key in another table.
CTo uniquely identify each record within its own table.
DTo allow duplicate values within a table for faster searches.
Attempts:
2 left
💡 Hint

Consider how tables relate to each other in a database.

❓ Comparison
advanced
2:00remaining
Super Key vs Candidate Key

Which of the following statements correctly distinguishes a super key from a candidate key?

AA super key is any key that uniquely identifies records; a candidate key is a minimal super key with no extra attributes.
BA super key must be chosen as the primary key; a candidate key cannot be primary.
CA candidate key can contain duplicate values; a super key cannot.
DA super key is always a foreign key; a candidate key is always a primary key.
Attempts:
2 left
💡 Hint

Think about minimality and uniqueness in keys.

❓ Reasoning
expert
2:00remaining
Identifying Keys in a Table

Consider a table Employees with columns: EmployeeID, Email, PhoneNumber, and DepartmentID. Which of the following is not a valid candidate key?

A<code>EmployeeID</code> because it uniquely identifies each employee.
B<code>Email</code> assuming each employee has a unique email address.
C<code>PhoneNumber</code> assuming some employees share the same phone number.
D<code>EmployeeID</code> and <code>Email</code> combined as a composite key.
Attempts:
2 left
💡 Hint

Candidate keys must uniquely identify records without duplicates.

Practice

(1/5)
1. Which key uniquely identifies each record in a database table and cannot have NULL values?
easy
A. Primary Key
B. Foreign Key
C. Candidate Key
D. Super Key

Solution

  1. Step 1: Understand the role of Primary Key

    The primary key uniquely identifies each record and must not be NULL.
  2. Step 2: Compare with other keys

    Foreign keys link tables, candidate keys are possible unique keys, super keys may have extra columns.
  3. Final Answer:

    Primary Key -> Option A
  4. Quick Check:

    Unique and not NULL = Primary Key [OK]
Hint: Primary key = unique + no NULL [OK]
Common Mistakes:
  • Confusing foreign key with primary key
  • Thinking candidate key is always primary
  • Assuming super key must be minimal
2. Which of the following is the correct syntax to declare a primary key on column id in SQL?
easy
A. CREATE TABLE t (id INT SUPER KEY);
B. CREATE TABLE t (id INT FOREIGN KEY);
C. CREATE TABLE t (id INT CANDIDATE KEY);
D. CREATE TABLE t (id INT PRIMARY KEY);

Solution

  1. Step 1: Recall SQL syntax for primary key

    Primary key is declared using PRIMARY KEY after the column definition.
  2. Step 2: Check other options

    Foreign key requires reference clause, candidate and super key are not SQL keywords.
  3. Final Answer:

    CREATE TABLE t (id INT PRIMARY KEY); -> Option D
  4. Quick Check:

    Primary key syntax = column INT PRIMARY KEY [OK]
Hint: Primary key uses PRIMARY KEY keyword in SQL [OK]
Common Mistakes:
  • Using FOREIGN KEY without REFERENCES
  • Trying to declare candidate or super key directly
  • Missing PRIMARY KEY keyword
3. Consider a table Orders with columns OrderID, CustomerID, and ProductID. If OrderID is the primary key and CustomerID is a foreign key referencing Customers table, what does this imply?
medium
A. OrderID uniquely identifies each order; CustomerID links to Customers table
B. CustomerID uniquely identifies each order; OrderID links to Customers table
C. ProductID is the primary key; CustomerID is a candidate key
D. OrderID and CustomerID together form a super key

Solution

  1. Step 1: Understand primary key role

    OrderID uniquely identifies each order record.
  2. Step 2: Understand foreign key role

    CustomerID links Orders to Customers table to maintain data consistency.
  3. Final Answer:

    OrderID uniquely identifies each order; CustomerID links to Customers table -> Option A
  4. Quick Check:

    Primary key = unique ID, foreign key = link [OK]
Hint: Primary key = unique; foreign key = link to another table [OK]
Common Mistakes:
  • Mixing primary and foreign key roles
  • Assuming foreign key is unique
  • Confusing candidate key with foreign key
4. A table has columns EmpID, Email, and Phone. The EmpID is set as primary key, but duplicate emails exist. What is the problem and how to fix it?
medium
A. Phone should be primary key instead of EmpID
B. Duplicate emails violate candidate key uniqueness; add UNIQUE constraint on Email
C. Primary key allows duplicates; change EmpID to foreign key
D. No problem; duplicates in Email are allowed with primary key on EmpID

Solution

  1. Step 1: Identify uniqueness requirements

    Primary key ensures EmpID is unique, but Email duplicates violate candidate key uniqueness if Email should be unique.
  2. Step 2: Fix by adding UNIQUE constraint

    To prevent duplicate emails, add UNIQUE constraint on Email column.
  3. Final Answer:

    Duplicate emails violate candidate key uniqueness; add UNIQUE constraint on Email -> Option B
  4. Quick Check:

    Unique candidate keys need UNIQUE constraint [OK]
Hint: Add UNIQUE constraint to enforce candidate key uniqueness [OK]
Common Mistakes:
  • Thinking primary key allows duplicates
  • Changing primary key without reason
  • Ignoring uniqueness of candidate keys
5. Given a table Students with columns StudentID, Email, and PhoneNumber, which of the following sets can be a super key?
hard
A. {StudentID, Email}
B. {Email, PhoneNumber}
C. All of the above
D. {StudentID}

Solution

  1. Step 1: Define super key

    A super key is any set of columns that uniquely identifies a record, even if it has extra columns.
  2. Step 2: Analyze each option

    StudentID alone uniquely identifies records; Email and PhoneNumber together can also uniquely identify; adding Email to StudentID still uniquely identifies (extra columns allowed).
  3. Final Answer:

    All of the above -> Option C
  4. Quick Check:

    Super key = unique set, extra columns allowed [OK]
Hint: Super key = unique columns, can include extras [OK]
Common Mistakes:
  • Thinking super key must be minimal
  • Confusing super key with candidate key
  • Assuming single column only
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard