0
0
MySQLquery~20 mins

INSERT INTO single row in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Single Row Insert Master
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 employees with columns 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);
AOne new row is added with id=1, name='Alice', age=30
BNo rows are added because the table is empty
CAn error occurs because the id column is missing
DTwo rows are added with the same data
Attempts:
2 left
💡 Hint
Think about what INSERT INTO does when the table is empty.
📝 Syntax
intermediate
2: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.
AINSERT INTO products (product_id, product_name, price) VALUES 101, 'Pen', 1.5;
BINSERT products INTO VALUES (101, 'Pen', 1.5);
CINSERT INTO products VALUES (101, 'Pen', 1.5);
DINSERT INTO products (product_id, product_name, price) VALUE (101, 'Pen', 1.5);
Attempts:
2 left
💡 Hint
Remember the correct order of keywords in an INSERT statement.
optimization
advanced
2: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?
AINSERT INTO orders SET order_id=5001, customer='John Doe', amount=250;
BINSERT INTO orders VALUES (5001, 'John Doe', 250);
CINSERT INTO orders (order_id, customer) VALUES (5001, 'John Doe');
DINSERT INTO orders (order_id, customer, amount) VALUES (5001, 'John Doe', 250);
Attempts:
2 left
💡 Hint
Consider clarity and explicitness in specifying columns.
🔧 Debug
advanced
2: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');
ABecause the table students does not exist
BBecause the age column is NOT NULL and no value was provided
CBecause the name column cannot be inserted without age
DBecause the id column is missing in the VALUES clause
Attempts:
2 left
💡 Hint
Check the NOT NULL constraints on columns.
🧠 Conceptual
expert
2: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');
AThe first insert succeeds; the second insert fails with a duplicate key error
BBoth inserts succeed and create two identical rows
CThe second insert updates the existing row with new data
DBoth inserts fail because primary keys cannot be inserted
Attempts:
2 left
💡 Hint
Think about primary key uniqueness constraints.