Bird
Raised Fist0
MySQLquery~20 mins

INSERT INTO multiple rows in MySQL - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Multi-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 inserting multiple rows?
Given the table students with columns id (auto-increment), name, and age, what will be the content of the table after running this query?

INSERT INTO students (name, age) VALUES ('Alice', 21), ('Bob', 22), ('Charlie', 23);
MySQL
SELECT * FROM students ORDER BY id;
A[{"id":1,"name":"Alice","age":21}]
B[{"id":1,"name":"Alice","age":21},{"id":2,"name":"Bob","age":22},{"id":3,"name":"Charlie","age":23}]
CSyntaxError
D[]
Attempts:
2 left
💡 Hint
Remember that INSERT INTO with multiple VALUES adds all rows in one query.
📝 Syntax
intermediate
2:00remaining
Which INSERT syntax is correct for multiple rows?
Which of the following queries correctly inserts multiple rows into a table products with columns product_name and price?
AINSERT INTO products (product_name, price) VALUE ('Pen', 1.5), ('Pencil', 1.0);
BINSERT INTO products (product_name, price) VALUES ('Pen', 1.5); ('Pencil', 1.0);
CINSERT INTO products VALUES ('Pen', 1.5), ('Pencil', 1.0);
DINSERT INTO products (product_name, price) VALUES ('Pen', 1.5), ('Pencil', 1.0);
Attempts:
2 left
💡 Hint
Check the keyword for multiple rows and punctuation.
❓ optimization
advanced
2:00remaining
Why prefer INSERT INTO multiple rows over multiple single-row inserts?
You want to add 1000 new users to a table. Which approach is more efficient and why?
AUse one INSERT INTO with 1000 rows in VALUES to reduce overhead.
BUse 1000 separate INSERT INTO statements, one per row, for clarity.
CUse DELETE then INSERT for all rows to refresh the table.
DUse UPDATE statements to add new rows one by one.
Attempts:
2 left
💡 Hint
Think about how many times the database has to process queries.
🔧 Debug
advanced
2:00remaining
Identify the error in this multi-row INSERT query
What error will this query cause?

INSERT INTO orders (order_id, product) VALUES (101, 'Book'), (102, 'Pen', 5);
ASyntaxError due to mismatched number of columns and values in second row
BNo error, inserts two rows correctly
CRuntime error: duplicate primary key
DTypeError: wrong data type for product
Attempts:
2 left
💡 Hint
Check if each row has the same number of values as columns specified.
🧠 Conceptual
expert
2:00remaining
What happens if you omit column names in multi-row INSERT?
Given a table employees with columns id (auto-increment), name, and department, what will happen if you run:

INSERT INTO employees VALUES (NULL, 'John', 'Sales'), (NULL, 'Jane', 'HR');
AOnly first row inserted, second causes error
BError because column names are missing
CRows inserted with auto-increment ids assigned automatically
DRows inserted but id remains NULL causing duplicates
Attempts:
2 left
💡 Hint
If you omit columns, values must match all columns in order.

Practice

(1/5)
1. What does the INSERT INTO statement with multiple rows do in MySQL?
easy
A. Updates multiple rows at once
B. Adds several records to a table in one command
C. Deletes multiple rows from a table
D. Creates a new table with multiple rows

Solution

  1. Step 1: Understand the purpose of INSERT INTO

    The INSERT INTO statement is used to add new data into a table.
  2. Step 2: Recognize multiple rows insertion

    When multiple rows are inserted, several sets of values are added in one command, saving time.
  3. Final Answer:

    Adds several records to a table in one command -> Option B
  4. Quick Check:

    Multiple rows insertion = Adds many records [OK]
Hint: Multiple rows use commas between parentheses [OK]
Common Mistakes:
  • Confusing INSERT with DELETE or UPDATE
  • Thinking it creates a new table
  • Believing it modifies existing rows
2. Which of the following is the correct syntax to insert multiple rows into a table named students with columns id and name?
easy
A. INSERT INTO students (id, name) VALUES (1, 'Alice'), (2, 'Bob');
B. INSERT INTO students VALUES (1, 'Alice'); (2, 'Bob');
C. INSERT INTO students (id, name) VALUES (1, 'Alice') AND (2, 'Bob');
D. INSERT INTO students (id, name) SET (1, 'Alice'), (2, 'Bob');

Solution

  1. Step 1: Check the correct use of VALUES and parentheses

    The correct syntax uses VALUES followed by multiple sets of values in parentheses separated by commas.
  2. Step 2: Identify the correct option

    INSERT INTO students (id, name) VALUES (1, 'Alice'), (2, 'Bob'); correctly uses VALUES (1, 'Alice'), (2, 'Bob') with commas separating rows.
  3. Final Answer:

    INSERT INTO students (id, name) VALUES (1, 'Alice'), (2, 'Bob'); -> Option A
  4. Quick Check:

    VALUES + multiple parentheses + commas = correct syntax [OK]
Hint: Use VALUES with comma-separated parentheses for rows [OK]
Common Mistakes:
  • Using semicolons between rows instead of commas
  • Using AND instead of commas
  • Using SET instead of VALUES
3. Given the table products(id INT, name VARCHAR(20)), what will be the result of this query?
INSERT INTO products (id, name) VALUES (1, 'Pen'), (2, 'Pencil');
SELECT * FROM products;
medium
A. [{id:1, name:'Pen'}]
B. Syntax error due to missing commas
C. [{id:1, name:'Pen'}, {id:2, name:'Pencil'}]
D. Empty result, no rows inserted

Solution

  1. Step 1: Understand the INSERT query

    The query inserts two rows: one with id=1 and name='Pen', another with id=2 and name='Pencil'.
  2. Step 2: Understand the SELECT query

    The SELECT query fetches all rows from the table, so it will show both inserted rows.
  3. Final Answer:

    [{id:1, name:'Pen'}, {id:2, name:'Pencil'}] -> Option C
  4. Quick Check:

    Multiple rows inserted = multiple rows returned [OK]
Hint: Multiple rows inserted appear in SELECT output [OK]
Common Mistakes:
  • Assuming only one row inserts
  • Thinking syntax error occurs without commas
  • Believing no rows are inserted
4. Identify the error in this query:
INSERT INTO employees (id, name) VALUES (1, 'John') (2, 'Jane');
medium
A. Extra semicolon inside VALUES
B. Using single quotes instead of double quotes
C. Missing column names
D. Missing comma between row values

Solution

  1. Step 1: Check syntax for multiple rows insertion

    Multiple rows must be separated by commas between parentheses.
  2. Step 2: Identify the missing comma

    The query misses a comma between (1, 'John') and (2, 'Jane').
  3. Final Answer:

    Missing comma between row values -> Option D
  4. Quick Check:

    Rows separated by commas, not just spaces [OK]
Hint: Separate each row with a comma inside VALUES [OK]
Common Mistakes:
  • Omitting commas between rows
  • Confusing quotes usage
  • Forgetting column list
5. You want to insert multiple rows into a table orders(order_id, product, quantity). You have this query:
INSERT INTO orders (order_id, product, quantity) VALUES (101, 'Book', 2), (102, 'Pen', 5), (101, 'Notebook', 3);

What problem might occur and how to fix it?
hard
A. Duplicate order_id 101 may cause error if order_id is PRIMARY KEY; fix by using unique IDs
B. Missing commas between rows; fix by adding commas
C. Wrong column order; fix by rearranging columns
D. Using single quotes for strings; fix by using double quotes

Solution

  1. Step 1: Identify duplicate primary key values

    If order_id is a PRIMARY KEY, duplicate values like 101 cause insertion errors.
  2. Step 2: Fix by ensuring unique keys

    Use unique order_id values for each row to avoid conflicts.
  3. Final Answer:

    Duplicate order_id 101 may cause error if order_id is PRIMARY KEY; fix by using unique IDs -> Option A
  4. Quick Check:

    Primary keys must be unique [OK]
Hint: Primary keys must be unique in multiple inserts [OK]
Common Mistakes:
  • Ignoring duplicate primary key errors
  • Confusing commas with semicolons
  • Misunderstanding string quoting rules
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