Bird
Raised Fist0
SQLquery~20 mins

Why UPDATE needs caution in SQL - Challenge Your Understanding

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
UPDATE Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
Effect of UPDATE without WHERE clause
Consider a table Employees with columns id, name, and salary. What will be the result after running this query?

UPDATE Employees SET salary = salary + 1000;

Assume the table initially has 3 rows with salaries 3000, 4000, and 5000.
SQL
UPDATE Employees SET salary = salary + 1000;
ANo salaries will change because WHERE clause is missing.
BOnly the first employee's salary will increase by 1000.
CAll 3 employees will have their salary increased by 1000.
DThe query will cause a syntax error.
Attempts:
2 left
💡 Hint
Think about what happens if you don't limit which rows to update.
❓ query_result
intermediate
2:00remaining
UPDATE with incorrect WHERE condition
Given a table Products with columns product_id, price, and category, what will be the result of this query?

UPDATE Products SET price = price * 0.9 WHERE category = 'Electronics' AND price > 1000;

Assume only one product has category 'Electronics' but its price is 900.
SQL
UPDATE Products SET price = price * 0.9 WHERE category = 'Electronics' AND price > 1000;
AAll Electronics products will have their price reduced by 10%.
BThe query will update all products regardless of category.
COnly products with price less than 1000 will be updated.
DNo product prices will change because no product meets both conditions.
Attempts:
2 left
💡 Hint
Check if any product matches both conditions in WHERE.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in UPDATE statement
Which option contains a syntax error in the UPDATE statement?
AUPDATE Orders SET status = 'Shipped' WHERE order_id = 10;
BUPDATE Products price = 20 WHERE product_id = 3;
CUPDATE Employees SET salary = salary + 500 WHERE department = 'Sales';
DUPDATE Customers SET city = 'Paris' WHERE id = 5;
Attempts:
2 left
💡 Hint
Look for missing keywords or punctuation.
🔧 Debug
advanced
2:00remaining
Unexpected data change after UPDATE
A developer runs this query:

UPDATE Inventory SET quantity = quantity - 1 WHERE product_id = 101;

But after running it, the quantity for all products decreased by 1. What is the most likely cause?
AThe WHERE clause was missing or incorrect, so all rows were updated.
BThe quantity column is not numeric, so subtraction failed.
CThe product_id 101 does not exist, so no rows updated.
DThe database automatically updates all rows when one is updated.
Attempts:
2 left
💡 Hint
Think about what happens if WHERE clause is ignored or wrong.
🧠 Conceptual
expert
2:00remaining
Why must UPDATE be used with caution in multi-user environments?
In a busy database with many users, why is it important to be cautious when running UPDATE statements?
ABecause UPDATE can lock rows or tables, causing delays or conflicts for other users.
BBecause UPDATE statements always delete data permanently.
CBecause UPDATE statements automatically create backups before changing data.
DBecause UPDATE statements cannot be rolled back once executed.
Attempts:
2 left
💡 Hint
Consider how databases handle multiple users changing data at the same time.

Practice

(1/5)
1. Why should you be careful when using the UPDATE statement without a WHERE clause?
easy
A. Because it will only update the first row.
B. Because it will delete the table.
C. Because it will create a new table.
D. Because it will update all rows in the table, possibly causing unwanted changes.

Solution

  1. Step 1: Understand the role of WHERE in UPDATE

    The WHERE clause limits which rows get updated. Without it, all rows are affected.
  2. Step 2: Consider the effect of missing WHERE

    Without WHERE, every row in the table changes, which can cause data loss or errors.
  3. Final Answer:

    Because it will update all rows in the table, possibly causing unwanted changes. -> Option D
  4. Quick Check:

    Missing WHERE updates all rows [OK]
Hint: Always use WHERE to limit rows in UPDATE [OK]
Common Mistakes:
  • Assuming UPDATE only changes one row by default
  • Forgetting WHERE clause causes full table update
  • Thinking UPDATE deletes data
2. Which of the following is the correct syntax to update the salary to 5000 for employees in department 10?
easy
A. UPDATE employees SET salary = 5000 department = 10;
B. UPDATE employees SET salary = 5000 WHERE department = 10;
C. UPDATE employees SET salary 5000 WHERE department = 10;
D. UPDATE employees salary = 5000 WHERE department = 10;

Solution

  1. Step 1: Recall correct UPDATE syntax

    The correct syntax is UPDATE table SET column = value WHERE condition;.
  2. Step 2: Check each option

    UPDATE employees SET salary = 5000 WHERE department = 10; matches the correct syntax exactly. Others miss keywords or punctuation.
  3. Final Answer:

    UPDATE employees SET salary = 5000 WHERE department = 10; -> Option B
  4. Quick Check:

    Correct UPDATE syntax uses SET and WHERE [OK]
Hint: UPDATE needs SET and WHERE for targeted changes [OK]
Common Mistakes:
  • Omitting SET keyword
  • Missing equal sign (=)
  • Leaving out WHERE clause
3. Given the table products with rows:
{id:1, price:100}, {id:2, price:200}, {id:3, price:300}
What will be the result after running:
UPDATE products SET price = price + 50 WHERE id > 1;
Then selecting all rows?
medium
A. [{id:1, price:150}, {id:2, price:250}, {id:3, price:350}]
B. [{id:1, price:150}, {id:2, price:200}, {id:3, price:300}]
C. [{id:1, price:100}, {id:2, price:250}, {id:3, price:350}]
D. [{id:1, price:100}, {id:2, price:200}, {id:3, price:300}]

Solution

  1. Step 1: Identify rows affected by WHERE clause

    The condition id > 1 affects rows with id 2 and 3 only.
  2. Step 2: Calculate new prices for affected rows

    Price for id 2: 200 + 50 = 250; Price for id 3: 300 + 50 = 350; id 1 remains 100.
  3. Final Answer:

    [{id:1, price:100}, {id:2, price:250}, {id:3, price:350}] -> Option C
  4. Quick Check:

    Only rows with id > 1 updated [OK]
Hint: Check WHERE condition carefully to know which rows update [OK]
Common Mistakes:
  • Updating all rows ignoring WHERE
  • Updating wrong rows by misreading condition
  • Changing values incorrectly
4. What is wrong with this SQL statement?
UPDATE employees SET salary = salary + 1000 WHERE;
medium
A. The WHERE clause is incomplete and causes a syntax error.
B. The SET keyword is missing.
C. The table name is incorrect.
D. The salary column cannot be updated.

Solution

  1. Step 1: Check the WHERE clause syntax

    The WHERE clause must have a condition after it. Here it is empty, causing error.
  2. Step 2: Verify other parts of the statement

    SET keyword and table name are correct; salary can be updated.
  3. Final Answer:

    The WHERE clause is incomplete and causes a syntax error. -> Option A
  4. Quick Check:

    Incomplete WHERE causes syntax error [OK]
Hint: Always provide a condition after WHERE [OK]
Common Mistakes:
  • Leaving WHERE empty
  • Forgetting condition after WHERE
  • Assuming WHERE is optional but incomplete
5. You want to increase the price by 10% only for products priced below 100. Which UPDATE statement is safest to avoid changing other rows?
hard
A. UPDATE products SET price = price * 1.10 WHERE price < 100;
B. UPDATE products SET price = price * 1.10;
C. UPDATE products SET price = price + 10 WHERE price < 100;
D. UPDATE products SET price = price * 1.10 WHERE price > 100;

Solution

  1. Step 1: Identify the condition to limit rows

    Only products with price less than 100 should be updated, so WHERE price < 100 is needed.
  2. Step 2: Choose correct price increase method

    Increasing by 10% means multiplying price by 1.10, not adding 10.
  3. Final Answer:

    UPDATE products SET price = price * 1.10 WHERE price < 100; -> Option A
  4. Quick Check:

    Use WHERE and correct math for safe updates [OK]
Hint: Use WHERE to limit rows and correct math for updates [OK]
Common Mistakes:
  • Forgetting WHERE and updating all rows
  • Adding fixed amount instead of percentage
  • Using wrong condition in WHERE
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