Challenge - 5 Problems
Primary Key Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this query on a table with PRIMARY KEY?
Given a table
Users with a PRIMARY KEY on column user_id, what will happen if you try to insert two rows with the same user_id?SQL
CREATE TABLE Users ( user_id INT PRIMARY KEY, username VARCHAR(50) ); INSERT INTO Users (user_id, username) VALUES (1, 'Alice'); INSERT INTO Users (user_id, username) VALUES (1, 'Bob');
Attempts:
2 left
💡 Hint
PRIMARY KEY enforces uniqueness for the column.
✗ Incorrect
A PRIMARY KEY column must have unique values. Trying to insert a duplicate value causes an error.
🧠 Conceptual
intermediate1:30remaining
Which statement about PRIMARY KEY is true?
Choose the correct statement about the PRIMARY KEY constraint in SQL.
Attempts:
2 left
💡 Hint
Think about uniqueness and nullability rules for PRIMARY KEY.
✗ Incorrect
PRIMARY KEY columns must be unique and cannot contain NULL values.
📝 Syntax
advanced2:00remaining
Which CREATE TABLE statement correctly defines a composite PRIMARY KEY?
Select the valid SQL syntax to create a table with a composite PRIMARY KEY on columns
order_id and product_id.Attempts:
2 left
💡 Hint
Composite keys are defined with parentheses and commas inside PRIMARY KEY clause.
✗ Incorrect
Option B correctly uses parentheses and commas to define a composite PRIMARY KEY.
🔧 Debug
advanced2:00remaining
Why does this table creation fail?
This SQL code fails to create the table. What is the reason?
SQL
CREATE TABLE Employees ( emp_id INT, emp_name VARCHAR(100), PRIMARY KEY emp_id );
Attempts:
2 left
💡 Hint
Check the syntax for PRIMARY KEY declaration.
✗ Incorrect
PRIMARY KEY columns must be enclosed in parentheses even if only one column is specified.
❓ optimization
expert2:30remaining
How does a PRIMARY KEY affect query performance?
Which statement best describes how a PRIMARY KEY constraint impacts database query performance?
Attempts:
2 left
💡 Hint
Think about how databases use indexes.
✗ Incorrect
PRIMARY KEY creates a unique index that helps the database find rows faster when searching by that key.