Challenge - 5 Problems
Single Row Insert Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the result of this INSERT statement?
Given the table employees with columns
Assume the table was empty before.
id (int), name (varchar), and age (int), what will be the result after running this query?INSERT INTO employees (id, name, age) VALUES (1, 'Alice', 30);Assume the table was empty before.
MySQL
INSERT INTO employees (id, name, age) VALUES (1, 'Alice', 30);
Attempts:
2 left
💡 Hint
Think about what INSERT INTO does when the table is empty.
✗ Incorrect
The INSERT INTO statement adds exactly one row with the specified values into the table. Since the table was empty, now it has one row with the given data.
📝 Syntax
intermediate2:00remaining
Which INSERT statement is syntactically correct?
Choose the correct INSERT statement to add a single row into the
products table with columns product_id, product_name, and price.Attempts:
2 left
💡 Hint
Remember the correct order of keywords in an INSERT statement.
✗ Incorrect
Option C uses the correct syntax: INSERT INTO table VALUES (...). Option C has wrong keyword order. Option C misses parentheses around VALUES. Option C uses VALUE instead of VALUES, which is invalid in MySQL.
❓ optimization
advanced2:00remaining
Which INSERT statement is more efficient for inserting a single row?
You want to insert a single row into the
orders table with columns order_id, customer, and amount. Which option is more efficient and why?Attempts:
2 left
💡 Hint
Consider clarity and explicitness in specifying columns.
✗ Incorrect
Option D explicitly lists columns and values, which is clearer and safer if table structure changes. Option D relies on column order, which can cause errors. Option D uses SET syntax which is valid but less common and may be less optimized. Option D misses the amount column, causing an error if it is NOT NULL.
🔧 Debug
advanced2:00remaining
Why does this INSERT statement fail?
Given the table
students with columns id (int, primary key), name (varchar), and age (int NOT NULL), why does this query fail?INSERT INTO students (id, name) VALUES (10, 'Emma');MySQL
INSERT INTO students (id, name) VALUES (10, 'Emma');
Attempts:
2 left
💡 Hint
Check the NOT NULL constraints on columns.
✗ Incorrect
The age column is NOT NULL, so it requires a value on insert. Omitting it causes an error.
🧠 Conceptual
expert2:00remaining
What happens if you insert a row with a duplicate primary key?
Consider a table
inventory with item_id as the primary key. What happens if you run this query twice?INSERT INTO inventory (item_id, item_name) VALUES (100, 'Notebook');MySQL
INSERT INTO inventory (item_id, item_name) VALUES (100, 'Notebook');
Attempts:
2 left
💡 Hint
Think about primary key uniqueness constraints.
✗ Incorrect
Primary keys must be unique. The first insert adds the row. The second insert tries to add a duplicate key and fails with an error.