0
0
SQLquery~5 mins

Primary keys and uniqueness in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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
Can a primary key column contain NULL values?
No, a primary key column cannot contain NULL values because it must uniquely identify every row, and NULL means unknown or missing.
Click to reveal answer
intermediate
What is the difference between a primary key and a unique constraint?
A primary key uniquely identifies rows and does not allow NULLs. A unique constraint also enforces uniqueness but allows NULL values depending on the database system.
Click to reveal answer
beginner
Why is it important to have a primary key in a table?
Having a primary key helps to quickly find, update, or delete specific rows. It also helps maintain data integrity by preventing duplicate rows.
Click to reveal answer
beginner
How do you define a primary key when creating a table in SQL?
You define a primary key using the PRIMARY KEY keyword in the CREATE TABLE statement, for example: CREATE TABLE Students (ID INT PRIMARY KEY, Name VARCHAR(50));
Click to reveal answer
Which of the following is true about a primary key?
AIt must be unique and cannot contain NULL values.
BIt can contain duplicate values.
CIt can contain multiple NULL values.
DIt is optional for every table.
What happens if you try to insert a duplicate value into a primary key column?
AThe database allows it without error.
BThe database converts the duplicate to NULL.
CThe database rejects the insert and shows an error.
DThe duplicate overwrites the existing row.
Which SQL keyword is used to enforce uniqueness on a column but allow NULL values?
ACHECK
BPRIMARY KEY
CFOREIGN KEY
DUNIQUE
Can a table have more than one primary key?
AYes, multiple primary keys are allowed.
BNo, only one primary key per table is allowed.
CYes, but only if they are composite keys.
DNo, primary keys are optional.
What is a composite primary key?
AA primary key made of multiple columns combined.
BA primary key that allows NULL values.
CA primary key that is automatically generated.
DA primary key that references another table.
Explain what a primary key is and why it is important in a database table.
Think about how you identify a person uniquely in real life.
You got /4 concepts.
    Describe the difference between a primary key and a unique constraint.
    Consider how strict each rule is about NULL values.
    You got /4 concepts.