Bird
Raised Fist0
SQLquery~20 mins

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

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Master of Single Row Inserts
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?
Consider a table employees with columns id (integer), name (text), and age (integer).
What will be the content of the table after running this query?
INSERT INTO employees (id, name, age) VALUES (1, 'Alice', 30);
SQL
SELECT * FROM employees;
A[]
B[{"id": 0, "name": "Alice", "age": 30}]
C[{"id": 1, "name": "Alice", "age": 30}]
D[{"id": 1, "name": null, "age": 30}]
Attempts:
2 left
💡 Hint
The INSERT statement adds one row with the specified values.
📝 Syntax
intermediate
2:00remaining
Which INSERT statement is syntactically correct?
Given a table products with columns product_id (int), product_name (text), and price (decimal), which of the following INSERT statements will run without syntax errors?
AINSERT INTO products (product_id, product_name, price) VALUES (101, 'Pen', 1.5);
BINSERT products INTO VALUES (101, 'Pen', 1.5);
CINSERT INTO products (product_id, product_name price) VALUES (101, 'Pen', 1.5);
DINSERT INTO products VALUES (101, 'Pen', 1.5);
Attempts:
2 left
💡 Hint
Check the order of keywords and commas between column names.
❓ optimization
advanced
2:00remaining
Which INSERT statement is more efficient for adding a single row?
You want to insert a single row into the orders table with columns order_id, customer, and total. Which option is more efficient and why?
AINSERT INTO orders VALUES (5001, 'John Doe', 250.75);
BINSERT INTO orders (order_id, customer, total) VALUES (5001, 'John Doe', 250.75);
CINSERT INTO orders SELECT 5001, 'John Doe', 250.75;
DINSERT INTO orders SET order_id=5001, customer='John Doe', total=250.75;
Attempts:
2 left
💡 Hint
If you provide values for all columns in order, you can omit column names.
🔧 Debug
advanced
2:00remaining
What error does this INSERT statement produce?
Given a table users with columns id (integer, primary key), username (text), and email (text), what error will this statement cause?
INSERT INTO users (id, username) VALUES (1, 'bob');
AError: Duplicate primary key
BNo error, row inserted with email as NULL
CSyntax error: missing value for email
DError: Column 'email' cannot be null
Attempts:
2 left
💡 Hint
If a column is not specified and allows NULL, it defaults to NULL.
🧠 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 is the result of this query?
INSERT INTO inventory (item_id, name) VALUES (10, 'Widget');
INSERT INTO inventory (item_id, name) VALUES (10, 'Gadget');
ASecond INSERT fails with a primary key violation error
BBoth rows inserted successfully, duplicates allowed
CSecond INSERT overwrites the first row
DFirst INSERT fails because the key is reused
Attempts:
2 left
💡 Hint
Primary keys must be unique in a table.

Practice

(1/5)
1. What does the SQL statement INSERT INTO students (name, age) VALUES ('Alice', 20); do?
easy
A. Deletes the student named Alice from the students table.
B. Adds a new student named Alice aged 20 to the students table.
C. Updates the age of all students to 20.
D. Creates a new table named students with columns name and age.

Solution

  1. Step 1: Understand the INSERT INTO statement

    The statement adds data to an existing table by specifying columns and values.
  2. Step 2: Match columns and values

    The columns are name and age, and the values are 'Alice' and 20, so a new row is added with these values.
  3. Final Answer:

    Adds a new student named Alice aged 20 to the students table. -> Option B
  4. Quick Check:

    INSERT INTO adds one row [OK]
Hint: INSERT INTO adds one row with matching columns and values [OK]
Common Mistakes:
  • Confusing INSERT with DELETE or UPDATE
  • Not matching columns and values order
  • Using wrong quotes for text values
2. Which of the following is the correct syntax to insert a single row into the table employees with columns id and name?
easy
A. INSERT employees (id, name) VALUES (1, 'John');
B. INSERT INTO employees (id, name) SET (1, 'John');
C. INSERT INTO employees VALUES id=1, name='John';
D. INSERT INTO employees (id, name) VALUES (1, 'John');

Solution

  1. Step 1: Recall correct INSERT syntax

    The correct syntax requires the keywords INSERT INTO, table name, columns in parentheses, then VALUES with matching values.
  2. Step 2: Check each option

    INSERT INTO employees (id, name) VALUES (1, 'John'); matches the correct syntax exactly; others have missing INTO, wrong assignment, or SET keyword which is invalid here.
  3. Final Answer:

    INSERT INTO employees (id, name) VALUES (1, 'John'); -> Option D
  4. Quick Check:

    INSERT INTO ... VALUES (...) is correct syntax [OK]
Hint: Always use INSERT INTO table (columns) VALUES (values) [OK]
Common Mistakes:
  • Omitting INTO keyword
  • Using SET instead of VALUES
  • Incorrect assignment inside VALUES
3. Given the table products with columns product_id (integer) and product_name (text), what will be the result of this query?
INSERT INTO products (product_id, product_name) VALUES (101, 'Pen');
medium
A. A new row with product_id 101 and product_name 'Pen' is added to products.
B. The query returns an error because product_name is text and needs double quotes.
C. The query updates product_id 101 to have product_name 'Pen'.
D. No change happens because INSERT INTO requires multiple rows.

Solution

  1. Step 1: Understand the INSERT INTO effect

    The query adds one new row with specified values to the products table.
  2. Step 2: Check syntax and data types

    Text values use single quotes in SQL, so 'Pen' is correct. No error occurs.
  3. Final Answer:

    A new row with product_id 101 and product_name 'Pen' is added to products. -> Option A
  4. Quick Check:

    INSERT INTO adds one row with given values [OK]
Hint: Text values need single quotes; INSERT adds one row [OK]
Common Mistakes:
  • Using double quotes for text values
  • Thinking INSERT updates existing rows
  • Believing INSERT requires multiple rows
4. Identify the error in this SQL statement:
INSERT INTO orders (order_id, customer) VALUES (123, John);
medium
A. The table name orders is invalid.
B. Missing parentheses around the VALUES keyword.
C. Missing single quotes around the text value John.
D. Using double quotes instead of single quotes for John.

Solution

  1. Step 1: Check the VALUES clause

    The value John is a text string and must be enclosed in single quotes in SQL.
  2. Step 2: Verify other syntax parts

    Parentheses around VALUES are correct; table name orders is valid; double quotes are not used here.
  3. Final Answer:

    Missing single quotes around the text value John. -> Option C
  4. Quick Check:

    Text values need single quotes [OK]
Hint: Text values must be in single quotes [OK]
Common Mistakes:
  • Forgetting quotes around text
  • Using double quotes instead of single
  • Misplacing parentheses
5. You have a table users with columns id (integer), username (text), and email (text). Which SQL statement correctly inserts a new user with id 5, username 'maria', and email 'maria@example.com'?
hard
A. INSERT INTO users (id, username, email) VALUES (5, 'maria', 'maria@example.com');
B. INSERT INTO users VALUES (5, maria, maria@example.com);
C. INSERT INTO users (id, username, email) VALUES ('5', 'maria', maria@example.com);
D. INSERT INTO users (id, username, email) SET (5, 'maria', 'maria@example.com');

Solution

  1. Step 1: Match columns and values correctly

    The columns id, username, and email are listed, so values must be in the same order and properly quoted.
  2. Step 2: Check value types and syntax

    Integer 5 does not need quotes, text values 'maria' and 'maria@example.com' need single quotes. INSERT INTO users (id, username, email) VALUES (5, 'maria', 'maria@example.com'); matches this exactly.
  3. Final Answer:

    INSERT INTO users (id, username, email) VALUES (5, 'maria', 'maria@example.com'); -> Option A
  4. Quick Check:

    Match columns and values with correct quotes [OK]
Hint: Match columns and values; quote text, not numbers [OK]
Common Mistakes:
  • Not quoting text values
  • Using SET instead of VALUES
  • Quoting integers unnecessarily
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