Challenge - 5 Problems
Default Value Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this INSERT with DEFAULT values?
Consider a table
users with columns id INT PRIMARY KEY, name VARCHAR(50) DEFAULT 'Guest', and age INT DEFAULT 18. What will be the result of this query?INSERT INTO users (id) VALUES (1);
SELECT * FROM users WHERE id = 1;
SQL
CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(50) DEFAULT 'Guest', age INT DEFAULT 18); INSERT INTO users (id) VALUES (1); SELECT * FROM users WHERE id = 1;
Attempts:
2 left
💡 Hint
If a column has a DEFAULT value and you don't provide a value, the default is used.
✗ Incorrect
When inserting a row without specifying columns that have DEFAULT values, the database fills those columns with their default values automatically.
🧠 Conceptual
intermediate1:30remaining
Which statement about DEFAULT values is true?
Choose the correct statement about DEFAULT values in SQL columns.
Attempts:
2 left
💡 Hint
Think about what happens when you don't mention a column in an INSERT.
✗ Incorrect
If a column is omitted in an INSERT, the database uses its DEFAULT value if defined. Explicit NULL insertion overrides the default.
📝 Syntax
advanced2:30remaining
Which CREATE TABLE statement correctly sets a DEFAULT value for a timestamp column?
You want to create a table
events with a created_at column that defaults to the current timestamp. Which option is correct?Attempts:
2 left
💡 Hint
Look for the correct syntax to use a function as a default value without parentheses.
✗ Incorrect
The correct syntax uses DEFAULT CURRENT_TIMESTAMP without parentheses or quotes. NOW() is a function call and not allowed as default in standard SQL.
❓ optimization
advanced2:00remaining
How can DEFAULT values improve INSERT performance?
Which of the following explains how using DEFAULT values can optimize database INSERT operations?
Attempts:
2 left
💡 Hint
Think about how omitting columns with defaults affects the size of the INSERT statement.
✗ Incorrect
By omitting columns that have DEFAULT values, INSERT statements are smaller and simpler, which can improve performance.
🔧 Debug
expert3:00remaining
Why does this INSERT fail despite DEFAULT values?
Given this table:
Why does this INSERT fail?
CREATE TABLE products (id INT PRIMARY KEY, name VARCHAR(50) DEFAULT 'Unknown', price DECIMAL(10,2) NOT NULL);
Why does this INSERT fail?
INSERT INTO products (id) VALUES (10);
Attempts:
2 left
💡 Hint
Check which columns require values and which have defaults.
✗ Incorrect
The price column has no DEFAULT and is NOT NULL, so it must be given a value in the INSERT.