Recall & Review
beginner
What is a PRIMARY KEY in a database table?
A PRIMARY KEY is a column or a set of columns that uniquely identifies each row in a table. It ensures no two rows have the same key value and that the key is never NULL.
Click to reveal answer
beginner
Can a PRIMARY KEY column contain NULL values?
No, a PRIMARY KEY column cannot contain NULL values. Every row must have a unique and non-null value for the PRIMARY KEY.
Click to reveal answer
beginner
How many PRIMARY KEYs can a table have?
A table can have only one PRIMARY KEY. This key can be made of one or multiple columns (called a composite key).
Click to reveal answer
beginner
What happens if you try to insert a duplicate value into a PRIMARY KEY column?
The database will reject the insert and return an error because PRIMARY KEY values must be unique.
Click to reveal answer
beginner
How do you define a PRIMARY KEY when creating a table in SQL?
You can define a PRIMARY KEY using the syntax: <br>
CREATE TABLE table_name (id INT PRIMARY KEY, ...); or by adding a constraint: <br>CREATE TABLE table_name (id INT, ..., PRIMARY KEY (id));Click to reveal answer
What is the main purpose of a PRIMARY KEY in a table?
✗ Incorrect
A PRIMARY KEY uniquely identifies each row and does not allow duplicates or NULLs.
How many PRIMARY KEYs can a table have?
✗ Incorrect
A table can have only one PRIMARY KEY, which can be a single or composite key.
Which of these is true about PRIMARY KEY columns?
✗ Incorrect
PRIMARY KEY columns must have unique values and cannot be NULL.
What happens if you insert a row with a duplicate PRIMARY KEY value?
✗ Incorrect
Inserting a duplicate PRIMARY KEY value causes an error because uniqueness is enforced.
Which SQL keyword is used to define a PRIMARY KEY?
✗ Incorrect
The PRIMARY KEY keyword defines the primary key constraint on a column or columns.
Explain what a PRIMARY KEY is and why it is important in a database table.
Think about how you find a unique item in a list.
You got /4 concepts.
Describe how to define a PRIMARY KEY when creating a new table in SQL.
Use CREATE TABLE statement with PRIMARY KEY.
You got /4 concepts.