Bird
Raised Fist0
SQLquery~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What does the SQL statement INSERT INTO table_name DEFAULT VALUES; do?
easy
A. Inserts a new row using all default values for columns
B. Deletes all rows from the table
C. Updates existing rows with default values
D. Selects all rows with default values

Solution

  1. Step 1: Understand the INSERT statement

    The statement inserts a new row into the table.
  2. Step 2: Recognize DEFAULT VALUES usage

    Using DEFAULT VALUES means the new row uses default values defined for each column.
  3. Final Answer:

    Inserts a new row using all default values for columns -> Option A
  4. Quick Check:

    INSERT ... DEFAULT VALUES inserts default row [OK]
Hint: DEFAULT VALUES inserts a row with all default column values [OK]
Common Mistakes:
  • Thinking it deletes or updates rows
  • Confusing DEFAULT VALUES with SELECT
  • Assuming it inserts NULLs instead of defaults
2. Which of the following is the correct syntax to insert a row with default values in SQL?
easy
A. INSERT INTO table_name VALUES (DEFAULT);
B. INSERT INTO table_name VALUES DEFAULT;
C. INSERT DEFAULT INTO table_name VALUES;
D. INSERT INTO table_name DEFAULT VALUES;

Solution

  1. Step 1: Recall correct syntax for default insertion

    The correct syntax is INSERT INTO table_name DEFAULT VALUES; to insert a row with all default values.
  2. Step 2: Check each option

    INSERT INTO table_name DEFAULT VALUES; matches the correct syntax exactly; others are invalid or incorrect.
  3. Final Answer:

    INSERT INTO table_name DEFAULT VALUES; -> Option D
  4. Quick Check:

    Correct syntax = INSERT INTO ... DEFAULT VALUES [OK]
Hint: Remember: DEFAULT VALUES comes after table name in INSERT [OK]
Common Mistakes:
  • Placing DEFAULT inside VALUES parentheses
  • Swapping DEFAULT and VALUES keywords
  • Using incorrect keyword order
3. Given the table users(id INT DEFAULT 0, name VARCHAR(20) DEFAULT 'guest'), what will be the result of INSERT INTO users DEFAULT VALUES; SELECT * FROM users; after running on an empty table?
medium
A. Empty result set
B. [{"id": 0, "name": "guest"}]
C. Syntax error
D. [{"id": NULL, "name": NULL}]

Solution

  1. Step 1: Understand table defaults

    The table has default values: id = 0, name = 'guest'.
  2. Step 2: Effect of INSERT DEFAULT VALUES

    Inserting default values adds a row with id=0 and name='guest'.
  3. Step 3: SELECT result

    After insertion, selecting all rows returns one row with those default values.
  4. Final Answer:

    [{"id": 0, "name": "guest"}] -> Option B
  5. Quick Check:

    Defaults inserted row = id 0, name guest [OK]
Hint: Defaults fill columns if no values given [OK]
Common Mistakes:
  • Expecting NULL instead of default values
  • Assuming syntax error due to DEFAULT VALUES
  • Thinking table remains empty
4. Consider the table products(id INT NOT NULL, name VARCHAR(20) DEFAULT 'unknown'). What error occurs when running INSERT INTO products DEFAULT VALUES;?
medium
A. Error: Column 'id' has no default and no value provided
B. No error, inserts row with NULL id and 'unknown' name
C. Syntax error due to DEFAULT VALUES usage
D. Inserts row with id=0 and name='unknown'

Solution

  1. Step 1: Check columns for defaults

    The 'id' column has no default and is NOT nullable.
  2. Step 2: Effect of INSERT DEFAULT VALUES

    Trying to insert default values fails because 'id' has no default and no value is given.
  3. Final Answer:

    Error: Column 'id' has no default and no value provided -> Option A
  4. Quick Check:

    Missing default for NOT NULL column causes error [OK]
Hint: All columns need defaults or allow NULL for DEFAULT VALUES [OK]
Common Mistakes:
  • Assuming NULL is inserted automatically
  • Thinking DEFAULT VALUES always works
  • Confusing syntax error with constraint error
5. You have a table orders(order_id INT PRIMARY KEY DEFAULT nextval('order_seq'), status VARCHAR(10) DEFAULT 'pending', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP). Which SQL statement correctly inserts a new order using all defaults except setting status to 'shipped'?
hard
A. INSERT INTO orders (order_id, status, created_at) VALUES (DEFAULT, DEFAULT, 'shipped');
B. INSERT INTO orders DEFAULT VALUES SET status = 'shipped';
C. INSERT INTO orders (status) VALUES ('shipped');
D. INSERT INTO orders (DEFAULT, 'shipped', DEFAULT);

Solution

  1. Step 1: Understand default and explicit values

    We want to use defaults for order_id and created_at, but set status explicitly.
  2. Step 2: Check each option

    INSERT INTO orders (status) VALUES ('shipped'); correctly lets the DBMS use defaults implicitly for unspecified columns order_id and created_at. INSERT INTO orders DEFAULT VALUES SET status = 'shipped'; is invalid syntax. INSERT INTO orders (order_id, status, created_at) VALUES (DEFAULT, DEFAULT, 'shipped'); incorrectly sets status to its default ('pending') and attempts to set created_at to 'shipped' causing a type mismatch error. INSERT INTO orders (DEFAULT, 'shipped', DEFAULT); is invalid syntax (missing VALUES keyword).
  3. Final Answer:

    INSERT INTO orders (status) VALUES ('shipped'); -> Option C
  4. Quick Check:

    Unspecified columns use their default values automatically [OK]
Hint: Unspecified columns in INSERT use column defaults [OK]
Common Mistakes:
  • Thinking omitting columns always causes errors
  • Using DEFAULT VALUES with SET syntax
  • Misplacing values and DEFAULT keywords in VALUES clause
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard