0
0
DBMS Theoryknowledge~20 mins

DML (INSERT, UPDATE, DELETE) in DBMS Theory - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
DML Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding INSERT statement behavior
What will happen if you execute the following SQL statement on a table Employees with columns id (primary key) and name where id 101 already exists?

INSERT INTO Employees (id, name) VALUES (101, 'Alice');
AThe existing row will be deleted and a new row inserted with id 101 and name 'Alice'.
BA new row with id 101 and name 'Alice' will be added, duplicating the primary key.
CThe statement will fail with a primary key violation error.
DThe row with id 101 will be updated to have name 'Alice'.
Attempts:
2 left
💡 Hint
Primary keys must be unique in a table.
🔍 Analysis
intermediate
2:00remaining
Effect of UPDATE with WHERE clause
Consider a table Products with columns product_id, price, and stock. What will be the effect of this SQL statement?

UPDATE Products SET price = price * 1.1 WHERE stock = 0;
AAll products will have their price increased by 10%.
BOnly products with zero stock will have their price increased by 10%.
COnly products with stock greater than zero will have their price increased by 10%.
DNo products will be updated because the WHERE clause is invalid.
Attempts:
2 left
💡 Hint
The WHERE clause filters which rows are updated.
📋 Factual
advanced
2:00remaining
DELETE statement without WHERE clause
What is the result of executing the following SQL command?

DELETE FROM Orders;
ADeletes all rows from the Orders table.
BCauses a syntax error because WHERE clause is required.
CDeletes only the first row in the Orders table.
DDeletes no rows because WHERE clause is missing.
Attempts:
2 left
💡 Hint
Think about what happens when no filter is applied in DELETE.
Comparison
advanced
2:00remaining
Difference between DELETE and TRUNCATE
Which of the following statements correctly describes a key difference between DELETE and TRUNCATE commands in SQL?
ADELETE removes rows one by one and can be rolled back; TRUNCATE removes all rows instantly and cannot be rolled back in most systems.
BDELETE removes all rows instantly and cannot be rolled back; TRUNCATE removes rows one by one and can be rolled back.
CBoth DELETE and TRUNCATE remove rows one by one and can be rolled back.
DDELETE only removes rows matching a condition; TRUNCATE requires a WHERE clause.
Attempts:
2 left
💡 Hint
Consider how each command handles transaction logs and rollback.
Reasoning
expert
3:00remaining
Predicting the final state after multiple DML operations
Given a table Inventory with columns item_id and quantity, initially containing:

item_id | quantity
1       | 10
2       | 5
3       | 0

What will be the contents of the table after executing these statements in order?

UPDATE Inventory SET quantity = quantity - 5 WHERE item_id = 1;
DELETE FROM Inventory WHERE quantity <= 0;
INSERT INTO Inventory (item_id, quantity) VALUES (3, 7);
A
&lt;pre&gt;item_id | quantity
1       | 5
2       | 5
3       | 0&lt;/pre&gt;
B
&lt;pre&gt;item_id | quantity
1       | 5
2       | 5&lt;/pre&gt;
C
&lt;pre&gt;item_id | quantity
1       | 10
2       | 5
3       | 7&lt;/pre&gt;
D
&lt;pre&gt;item_id | quantity
1       | 5
2       | 5
3       | 7&lt;/pre&gt;
Attempts:
2 left
💡 Hint
Apply each statement step-by-step and watch how rows change or get deleted.