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.
Click to reveal answer
beginner
How do you declare a primary key when creating a table in MySQL?
You declare a primary key using the
PRIMARY KEY keyword after the column definition or at the end of the column list in the CREATE TABLE statement.Click to reveal answer
beginner
Can a primary key column contain NULL values?
No, a primary key column cannot contain NULL values because it must uniquely identify each row.
Click to reveal answer
beginner
What happens if you try to insert duplicate values into a primary key column?
The database will reject the insert and return an error because primary keys must be unique.
Click to reveal answer
beginner
Show an example of declaring a primary key on a single column in MySQL.
Example:<br>
CREATE TABLE users (<br> id INT NOT NULL,<br> name VARCHAR(100),<br> PRIMARY KEY (id)<br>);
Click to reveal answer
Which of the following is true about a primary key?
✗ Incorrect
A primary key must uniquely identify each row and cannot contain NULL values.
How do you declare a primary key on the 'id' column when creating a table?
✗ Incorrect
The correct syntax is PRIMARY KEY (id) inside the CREATE TABLE statement.
What will happen if you insert two rows with the same primary key value?
✗ Incorrect
Primary key values must be unique, so the second insert will fail.
Can a table have more than one primary key?
✗ Incorrect
A table can have only one primary key, which can be a single or composite key.
Which keyword is used to declare a primary key in MySQL?
✗ Incorrect
The PRIMARY KEY keyword declares the primary key constraint.
Explain what a primary key is and why it is important in a database table.
Think about how you find a unique person in a list.
You got /3 concepts.
Describe how to declare a primary key in a MySQL CREATE TABLE statement with an example.
Look at the structure of CREATE TABLE and where PRIMARY KEY fits.
You got /3 concepts.