0
0
SQLquery~5 mins

PRIMARY KEY constraint 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 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?
ATo uniquely identify each row
BTo allow duplicate values
CTo store large text data
DTo allow NULL values
How many PRIMARY KEYs can a table have?
AOne
BTwo
CAs many as columns
DNone
Which of these is true about PRIMARY KEY columns?
AThey can contain NULL values
BThey can have duplicate values
CThey must be unique and not NULL
DThey are optional
What happens if you insert a row with a duplicate PRIMARY KEY value?
AThe old row is deleted
BThe row is inserted successfully
CThe duplicate is ignored
DThe database throws an error
Which SQL keyword is used to define a PRIMARY KEY?
AUNIQUE
BPRIMARY KEY
CFOREIGN KEY
DINDEX
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.