0
0
SQLquery~20 mins

UPDATE single column in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
SQL Update Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Update a single column for specific rows
Given a table Employees with columns id, name, and salary, what will be the result of this query?

UPDATE Employees SET salary = salary + 500 WHERE id = 3;

Assume the original salary for id = 3 is 3000.
SQL
SELECT id, name, salary FROM Employees ORDER BY id;
A[{"id":1,"name":"Alice","salary":4000},{"id":2,"name":"Bob","salary":4000},{"id":3,"name":"Charlie","salary":3500}]
B[{"id":1,"name":"Alice","salary":4000},{"id":2,"name":"Bob","salary":3500},{"id":3,"name":"Charlie","salary":3000}]
C[{"id":1,"name":"Alice","salary":3500},{"id":2,"name":"Bob","salary":3500},{"id":3,"name":"Charlie","salary":3500}]
D[{"id":1,"name":"Alice","salary":4000},{"id":2,"name":"Bob","salary":3500},{"id":3,"name":"Charlie","salary":3500}]
Attempts:
2 left
💡 Hint
Only the row with id = 3 will have its salary increased by 500.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in UPDATE statement
Which option contains a syntax error in updating a single column in the Products table to set price to 20 where id is 5?
AUPDATE Products SET price = 20 WHERE id = 5;
BUPDATE Products SET price = 20 WHERE id = 5
CUPDATE Products SET price 20 WHERE id = 5;
DUPDATE Products SET price = 20 WHERE id == 5;
Attempts:
2 left
💡 Hint
Check for missing operators or incorrect syntax in the SET clause.
optimization
advanced
2:00remaining
Optimizing UPDATE for large tables
You want to increase the stock column by 10 for all products in category 'Books' in a large Inventory table. Which query is the most efficient?
AUPDATE Inventory SET stock = stock + 10 WHERE category = 'Books';
BUPDATE Inventory SET stock = stock + 10;
CUPDATE Inventory SET stock = stock + 10 WHERE category LIKE '%Books%';
DUPDATE Inventory SET stock = stock + 10 WHERE category IN (SELECT category FROM Inventory WHERE category = 'Books');
Attempts:
2 left
💡 Hint
Focus on limiting the update only to relevant rows without unnecessary overhead.
🔧 Debug
advanced
2:00remaining
Why does this UPDATE not change any rows?
Given the table Users with columns id, username, and active, why does this query not update any rows?

UPDATE Users SET active = 1 WHERE username = 'john_doe';

Assume there is a user with username 'John_Doe' (capital J).
ABecause the table Users does not have a column named active.
BBecause the WHERE clause is case-sensitive and 'john_doe' does not match 'John_Doe'.
CBecause the UPDATE statement is missing a semicolon at the end.
DBecause the active column is already 1 for all users.
Attempts:
2 left
💡 Hint
Think about how string comparisons work in SQL by default.
🧠 Conceptual
expert
2:00remaining
Effect of UPDATE without WHERE clause
What happens if you run this query on the Orders table?

UPDATE Orders SET status = 'shipped';
AAll rows in the Orders table will have their status set to 'shipped'.
BOnly the first row in the Orders table will be updated.
CNo rows will be updated because WHERE clause is missing.
DThe query will cause a syntax error due to missing WHERE clause.
Attempts:
2 left
💡 Hint
Consider what happens when UPDATE is run without any filter.