0
0
SQLquery~20 mins

INSERT with DEFAULT values in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of INSERT with DEFAULT values
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the result of this INSERT statement?

Given the table users(id SERIAL PRIMARY KEY, name TEXT DEFAULT 'Anonymous', age INT DEFAULT 18), what will be the content of the table after running this query?

INSERT INTO users DEFAULT VALUES;
SQL
CREATE TABLE users(id SERIAL PRIMARY KEY, name TEXT DEFAULT 'Anonymous', age INT DEFAULT 18);
INSERT INTO users DEFAULT VALUES;
SELECT * FROM users;
A[{"id": 1, "name": "Anonymous", "age": 18}]
BSyntaxError
C[{"id": 1, "name": null, "age": null}]
D[]
Attempts:
2 left
💡 Hint

Think about what happens when you insert with DEFAULT VALUES and the table has default values defined.

📝 Syntax
intermediate
1:30remaining
Which INSERT statement is syntactically correct to insert default values into all columns?

Choose the correct SQL statement to insert a new row with all default values into a table products.

AINSERT INTO products DEFAULT VALUES;
BINSERT INTO products VALUES DEFAULT;
CINSERT INTO products VALUES (DEFAULT);
DINSERT INTO products SET DEFAULT VALUES;
Attempts:
2 left
💡 Hint

Remember the exact syntax for inserting default values without specifying columns.

query_result
advanced
2:00remaining
What happens when you mix DEFAULT and explicit values in INSERT?

Given the table orders(id SERIAL PRIMARY KEY, status TEXT DEFAULT 'pending', quantity INT DEFAULT 1), what will be the result of this query?

INSERT INTO orders(status, quantity) VALUES (DEFAULT, 5);
SELECT * FROM orders;
SQL
CREATE TABLE orders(id SERIAL PRIMARY KEY, status TEXT DEFAULT 'pending', quantity INT DEFAULT 1);
INSERT INTO orders(status, quantity) VALUES (DEFAULT, 5);
SELECT * FROM orders;
A[{"id": 1, "status": null, "quantity": 5}]
B[{"id": 1, "status": "DEFAULT", "quantity": 5}]
CSyntaxError
D[{"id": 1, "status": "pending", "quantity": 5}]
Attempts:
2 left
💡 Hint

Consider what DEFAULT means when used as a value in an INSERT statement.

🔧 Debug
advanced
2:00remaining
Why does this INSERT with DEFAULT VALUES fail?

Given the table employees(id INT PRIMARY KEY, name TEXT DEFAULT 'John Doe'), why does this query fail?

INSERT INTO employees DEFAULT VALUES;
ABecause 'name' column default is invalid
BBecause DEFAULT VALUES is not supported on this table
CBecause the column 'id' has no default and is NOT NULL
DBecause the table has no columns
Attempts:
2 left
💡 Hint

Check which columns require values and if they have defaults.

🧠 Conceptual
expert
1:30remaining
What is the effect of using DEFAULT VALUES in an INSERT statement?

Choose the best description of what INSERT INTO table DEFAULT VALUES; does.

AInserts a new row with all columns set to zero or empty string
BInserts a new row where all columns get their default values, or NULL if no default is defined
CInserts a new row with all columns set to NULL, ignoring defaults
DDeletes all rows and inserts a default row
Attempts:
2 left
💡 Hint

Think about how default values work in SQL inserts.