0
0
SQLquery~20 mins

DEFAULT values in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Default Value Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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;
A(1, 'Guest', 18)
B(1, NULL, NULL)
C(1, '', 0)
DError: Missing values for name and age
Attempts:
2 left
💡 Hint
If a column has a DEFAULT value and you don't provide a value, the default is used.
🧠 Conceptual
intermediate
1:30remaining
Which statement about DEFAULT values is true?
Choose the correct statement about DEFAULT values in SQL columns.
ADEFAULT values are used only when explicitly specified in the INSERT statement.
BDEFAULT values are ignored if NULL is inserted explicitly into the column.
CDEFAULT values can only be numeric constants.
DDEFAULT values are applied when the column is omitted in the INSERT statement.
Attempts:
2 left
💡 Hint
Think about what happens when you don't mention a column in an INSERT.
📝 Syntax
advanced
2: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?
ACREATE TABLE events (id INT PRIMARY KEY, created_at TIMESTAMP DEFAULT NOW());
BCREATE TABLE events (id INT PRIMARY KEY, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
CCREATE TABLE events (id INT PRIMARY KEY, created_at TIMESTAMP DEFAULT 'CURRENT_TIMESTAMP');
DCREATE TABLE events (id INT PRIMARY KEY, created_at TIMESTAMP DEFAULT current_timestamp());
Attempts:
2 left
💡 Hint
Look for the correct syntax to use a function as a default value without parentheses.
optimization
advanced
2:00remaining
How can DEFAULT values improve INSERT performance?
Which of the following explains how using DEFAULT values can optimize database INSERT operations?
ADEFAULT values require explicit values in every INSERT, increasing data size.
BDEFAULT values force the database to compute values on every INSERT, slowing performance.
CDEFAULT values reduce the amount of data sent in INSERT statements by omitting columns with defaults.
DDEFAULT values cause the database to lock the table during INSERTs.
Attempts:
2 left
💡 Hint
Think about how omitting columns with defaults affects the size of the INSERT statement.
🔧 Debug
expert
3:00remaining
Why does this INSERT fail despite DEFAULT values?
Given this table:
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);
ABecause price has no DEFAULT and is NOT NULL, so it must be provided.
BBecause DEFAULT values cannot be used with DECIMAL columns.
CBecause id is missing in the INSERT statement.
DBecause name DEFAULT value is invalid for VARCHAR columns.
Attempts:
2 left
💡 Hint
Check which columns require values and which have defaults.