Bird
0
0

Which SQL statement correctly creates this table with a composite primary key?

hard📝 Application Q9 of 15
SQL - Table Constraints
You want to create a table LibraryLoans to track which books are loaned to which members. Each loan is uniquely identified by member_id and book_id. You also want to record the loan_date. Which SQL statement correctly creates this table with a composite primary key?
ACREATE TABLE LibraryLoans ( member_id INT PRIMARY KEY, book_id INT PRIMARY KEY, loan_date DATE );
BCREATE TABLE LibraryLoans ( member_id INT, book_id INT, loan_date DATE, PRIMARY KEY member_id, book_id );
CCREATE TABLE LibraryLoans ( member_id INT, book_id INT, loan_date DATE, PRIMARY KEY (member_id, book_id) );
DCREATE TABLE LibraryLoans ( member_id INT, book_id INT, loan_date DATE, UNIQUE (member_id, book_id) );
Step-by-Step Solution
Solution:
  1. Step 1: Understand composite primary key syntax

    Composite primary key requires parentheses around columns.
  2. Step 2: Evaluate options

    CREATE TABLE LibraryLoans ( member_id INT, book_id INT, loan_date DATE, PRIMARY KEY (member_id, book_id) ); correctly defines composite primary key on member_id and book_id.
  3. Final Answer:

    CREATE TABLE LibraryLoans ( member_id INT, book_id INT, loan_date DATE, PRIMARY KEY (member_id, book_id) ); -> Option C
  4. Quick Check:

    Composite primary key syntax requires parentheses [OK]
Quick Trick: Use parentheses to define composite primary keys [OK]
Common Mistakes:
MISTAKES
  • Defining multiple primary keys separately
  • Omitting parentheses in primary key definition
  • Using UNIQUE instead of PRIMARY KEY

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes