0
0
SQLquery~20 mins

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

Choose your learning style9 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.