0
0
SQLquery~20 mins

INSERT with specific columns in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of INSERT with specific columns
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What rows are inserted by this query?
Given the table Employees with columns id, name, department, and salary, what rows will be added after running this query?

INSERT INTO Employees (id, name) VALUES (101, 'Alice'), (102, 'Bob');
SQL
INSERT INTO Employees (id, name) VALUES (101, 'Alice'), (102, 'Bob');
ATwo rows inserted: (101, 'Alice', 'Unknown', 0) and (102, 'Bob', 'Unknown', 0)
BTwo rows inserted: (101, 'Alice', '', 0) and (102, 'Bob', '', 0)
CTwo rows inserted: (101, 'Alice', NULL, NULL) and (102, 'Bob', NULL, NULL)
DNo rows inserted because department and salary are missing
Attempts:
2 left
💡 Hint
Columns not listed in the INSERT get default values or NULL if no default.
📝 Syntax
intermediate
2:00remaining
Which INSERT statement is syntactically correct?
Choose the correct INSERT statement that adds a row with id=201 and name='Charlie' into the Users table with columns id, name, and email.
AINSERT INTO Users (id, name) VALUES (201, 'Charlie');
BINSERT INTO Users (id, name) VALUE (201, 'Charlie');
CINSERT INTO Users (id, name, email) VALUES (201, 'Charlie');
DINSERT INTO Users VALUES (201, 'Charlie');
Attempts:
2 left
💡 Hint
Check if the number of columns matches the number of values and syntax keywords.
optimization
advanced
2:00remaining
Which INSERT is more efficient for adding multiple rows with partial columns?
You want to insert 1000 rows into the Products table with columns product_id, name, price, and stock. You only have product_id and name data. Which query is better for performance?
AINSERT INTO Products VALUES (1, 'Pen', NULL, NULL), (2, 'Pencil', NULL, NULL), ..., (1000, 'Eraser', NULL, NULL);
BINSERT INTO Products (product_id, name) VALUES (1, 'Pen'), (2, 'Pencil'), ..., (1000, 'Eraser');
CINSERT INTO Products (product_id, name, price, stock) SELECT product_id, name, NULL, NULL FROM TempProducts;
DINSERT INTO Products SELECT product_id, name FROM TempProducts;
Attempts:
2 left
💡 Hint
Consider specifying only needed columns and values directly.
🔧 Debug
advanced
2:00remaining
Why does this INSERT fail?
Given table Orders with columns order_id, customer, date, and status (status has no default and is NOT NULL), why does this query fail?

INSERT INTO Orders (order_id, customer, date) VALUES (5001, 'John Doe', '2024-06-01');
ABecause the <code>customer</code> value is too long
BBecause the <code>date</code> format is invalid
CBecause <code>order_id</code> must be auto-generated and cannot be inserted
DBecause the <code>status</code> column is NOT NULL and missing in the INSERT
Attempts:
2 left
💡 Hint
Check constraints on columns not included in the INSERT.
🧠 Conceptual
expert
2:00remaining
What happens if you insert with specific columns but omit a NOT NULL column with a default?
Consider a table Inventory with columns item_id (PK), name, quantity NOT NULL DEFAULT 0, and location. What will be the value of quantity after this query?

INSERT INTO Inventory (item_id, name) VALUES (3001, 'Notebook');
AThe <code>quantity</code> will be 0 because of the default value
BThe <code>quantity</code> will be NULL because it was omitted
CThe INSERT will fail because <code>quantity</code> is NOT NULL and missing
DThe <code>quantity</code> will be set to an empty string
Attempts:
2 left
💡 Hint
Think about how default values work with NOT NULL columns.