Challenge - 5 Problems
Master of INSERT with specific columns
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What rows are inserted by this query?
Given the table Employees with columns
id, name, department, and salary, what rows will be added after running this query?INSERT INTO Employees (id, name) VALUES (101, 'Alice'), (102, 'Bob');
SQL
INSERT INTO Employees (id, name) VALUES (101, 'Alice'), (102, 'Bob');
Attempts:
2 left
💡 Hint
Columns not listed in the INSERT get default values or NULL if no default.
✗ Incorrect
When you specify columns in INSERT, only those columns get values. Others get NULL if allowed or default values if defined. Here, department and salary get NULL.
📝 Syntax
intermediate2:00remaining
Which INSERT statement is syntactically correct?
Choose the correct INSERT statement that adds a row with id=201 and name='Charlie' into the
Users table with columns id, name, and email.Attempts:
2 left
💡 Hint
Check if the number of columns matches the number of values and syntax keywords.
✗ Incorrect
Option A correctly specifies columns and matching values. Option A misses email column value. Option A has fewer values than columns. Option A uses wrong keyword VALUE instead of VALUES.
❓ optimization
advanced2:00remaining
Which INSERT is more efficient for adding multiple rows with partial columns?
You want to insert 1000 rows into the
Products table with columns product_id, name, price, and stock. You only have product_id and name data. Which query is better for performance?Attempts:
2 left
💡 Hint
Consider specifying only needed columns and values directly.
✗ Incorrect
Option B inserts only needed columns with values directly, which is efficient. Option B inserts NULLs explicitly, which is unnecessary. Option B uses SELECT but requires a TempProducts table. Option B misses columns and values mismatch.
🔧 Debug
advanced2:00remaining
Why does this INSERT fail?
Given table
Orders with columns order_id, customer, date, and status (status has no default and is NOT NULL), why does this query fail?INSERT INTO Orders (order_id, customer, date) VALUES (5001, 'John Doe', '2024-06-01');
Attempts:
2 left
💡 Hint
Check constraints on columns not included in the INSERT.
✗ Incorrect
The
status column is NOT NULL and has no default, so it must be included in the INSERT or the query fails.🧠 Conceptual
expert2:00remaining
What happens if you insert with specific columns but omit a NOT NULL column with a default?
Consider a table
Inventory with columns item_id (PK), name, quantity NOT NULL DEFAULT 0, and location. What will be the value of quantity after this query?INSERT INTO Inventory (item_id, name) VALUES (3001, 'Notebook');
Attempts:
2 left
💡 Hint
Think about how default values work with NOT NULL columns.
✗ Incorrect
If a NOT NULL column has a default, omitting it in INSERT sets it to the default value automatically.