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?
✗ Incorrect
DEFAULT sets a preset value for a column if no value is given during insertion.
Which of the following is a valid DEFAULT value for a TIMESTAMP column?
✗ Incorrect
CURRENT_TIMESTAMP is a function that returns the current date and time, valid as a DEFAULT for TIMESTAMP.
If a column has DEFAULT 100 and you insert a row without specifying that column, what value will it have?
✗ Incorrect
The column will automatically get the DEFAULT value 100.
How do you change the DEFAULT value of an existing column in SQL?
✗ Incorrect
You use ALTER TABLE with ALTER COLUMN and SET DEFAULT to change the default value.
Can DEFAULT values be expressions or functions?
✗ Incorrect
DEFAULT values can be functions like CURRENT_TIMESTAMP to set dynamic defaults.
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.