Recall & Review
beginner
What is a composite primary key in a database?
A composite primary key is a primary key made up of two or more columns that together uniquely identify each row in a table.
Click to reveal answer
beginner
Why would you use a composite primary key instead of a single column primary key?
You use a composite primary key when no single column can uniquely identify a row, but a combination of columns can.
Click to reveal answer
beginner
How do you define a composite primary key in SQL?
You list multiple columns inside the PRIMARY KEY clause, separated by commas, like: PRIMARY KEY (column1, column2).
Click to reveal answer
intermediate
Can a composite primary key contain NULL values in any of its columns?
No, all columns in a composite primary key must have NOT NULL values to ensure uniqueness.
Click to reveal answer
beginner
Example: What is the composite primary key in this table definition?
CREATE TABLE Enrollment (
student_id INT,
course_id INT,
enrollment_date DATE,
PRIMARY KEY (student_id, course_id)
);
The composite primary key is the combination of student_id and course_id columns. Together, they uniquely identify each enrollment record.
Click to reveal answer
What does a composite primary key consist of?
✗ Incorrect
A composite primary key uses multiple columns together to uniquely identify each row.
Which SQL syntax correctly defines a composite primary key?
✗ Incorrect
The correct syntax uses parentheses around the columns separated by commas.
Can any column in a composite primary key contain NULL values?
✗ Incorrect
All columns in a primary key must be NOT NULL to guarantee uniqueness.
Why might you choose a composite primary key?
✗ Incorrect
Composite keys are used when a single column is not enough to uniquely identify rows.
In the table Enrollment(student_id, course_id), which is the best primary key?
✗ Incorrect
The combination of student_id and course_id uniquely identifies each enrollment.
Explain what a composite primary key is and why it is useful.
Think about how two or more columns together can identify a record uniquely.
You got /4 concepts.
Describe how to define a composite primary key in SQL with an example.
Remember the parentheses and commas between column names.
You got /3 concepts.