0
0
SQLquery~5 mins

DEFAULT values in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the DEFAULT value in a SQL table column?
The DEFAULT value sets a preset value for a column when no value is provided during data insertion. It helps avoid NULLs and ensures consistent data.
Click to reveal answer
beginner
How do you define a DEFAULT value for a column in SQL?
You use the DEFAULT keyword followed by the value when creating or altering a table column, for example: age INT DEFAULT 18.
Click to reveal answer
intermediate
Can a DEFAULT value be a function in SQL? Give an example.
Yes, a DEFAULT value can be a function. For example, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP sets the current time automatically.
Click to reveal answer
beginner
What happens if you insert a row without specifying a column that has a DEFAULT value?
The column automatically gets the DEFAULT value specified in the table definition instead of NULL or an error.
Click to reveal answer
intermediate
Is it possible to change the DEFAULT value of an existing column? How?
Yes, you can change it using the ALTER TABLE statement with ALTER COLUMN and SET DEFAULT, for example: ALTER TABLE users ALTER COLUMN age SET DEFAULT 21;.
Click to reveal answer
What does the DEFAULT keyword do in SQL?
ASets a preset value for a column when no value is provided
BDeletes a column from a table
CChanges the data type of a column
DCreates a new table
Which of the following is a valid DEFAULT value for a TIMESTAMP column?
ADEFAULT 0
BDEFAULT TRUE
CDEFAULT CURRENT_TIMESTAMP
DDEFAULT 'hello'
If a column has DEFAULT 100 and you insert a row without specifying that column, what value will it have?
A100
B0
CNULL
DError
How do you change the DEFAULT value of an existing column in SQL?
AYou cannot change DEFAULT values
BDROP COLUMN and add a new one
CUPDATE the table
DALTER TABLE ... ALTER COLUMN ... SET DEFAULT ...
Can DEFAULT values be expressions or functions?
ANo, only constants
BYes, for example CURRENT_TIMESTAMP
COnly strings
DOnly numbers
Explain what DEFAULT values are in SQL and why they are useful.
Think about what happens if you forget to give a value for a column.
You got /4 concepts.
    Describe how to set and change DEFAULT values for columns in SQL tables.
    Consider both table creation and modifying existing tables.
    You got /3 concepts.