0
0
PostgreSQLquery~5 mins

PRIMARY KEY and SERIAL behavior in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a PRIMARY KEY in a PostgreSQL table?
A PRIMARY KEY is a column or set of columns that uniquely identifies each row in a table. It ensures no duplicate or NULL values exist in those columns.
Click to reveal answer
beginner
What does the SERIAL keyword do in PostgreSQL?
SERIAL creates an auto-incrementing integer column. It automatically generates a unique number for each new row inserted.
Click to reveal answer
beginner
Can a SERIAL column be used as a PRIMARY KEY?
Yes, a SERIAL column is often used as a PRIMARY KEY because it provides unique, automatically generated values for each row.
Click to reveal answer
beginner
What happens if you insert a row without specifying a value for a SERIAL column?
PostgreSQL automatically assigns the next number in the sequence to the SERIAL column for that row.
Click to reveal answer
intermediate
How does PostgreSQL ensure uniqueness for a PRIMARY KEY?
PostgreSQL creates a unique index on the PRIMARY KEY column(s) to prevent duplicate values and enforce uniqueness.
Click to reveal answer
What is the main purpose of a PRIMARY KEY in a table?
ATo store large text data
BTo allow NULL values
CTo speed up SELECT queries only
DTo uniquely identify each row
What type of data does SERIAL create in PostgreSQL?
AFixed-length string
BFloating point number
CAuto-incrementing integer
DBoolean value
If you insert a row without specifying a SERIAL column value, what happens?
AAn error occurs
BPostgreSQL assigns the next sequence number automatically
CThe column is set to NULL
DThe row is ignored
Can a PRIMARY KEY column contain NULL values?
ANo, PRIMARY KEY columns cannot be NULL
BOnly if it is a SERIAL column
CYes, always
DOnly if the table is empty
What does PostgreSQL create automatically when you define a PRIMARY KEY?
AA unique index on the key column(s)
BA foreign key constraint
CA trigger for inserts
DA default value
Explain what a PRIMARY KEY is and why it is important in a database table.
Think about how you find a specific item in a list without confusion.
You got /4 concepts.
    Describe how the SERIAL keyword works in PostgreSQL and how it relates to PRIMARY KEY columns.
    Imagine numbering pages in a book automatically.
    You got /4 concepts.