0
0
SQLquery~20 mins

UPDATE without WHERE (danger) in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Safe Updater
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output after running this UPDATE?

Consider a table Employees with columns id, name, and salary. Initially, the table has these rows:

id | name    | salary
---+---------+--------
1  | Alice   | 5000
2  | Bob     | 6000
3  | Charlie | 7000

What will be the salaries of all employees after running this query?

UPDATE Employees SET salary = 10000;
SQL
UPDATE Employees SET salary = 10000;
AOnly Alice's salary is 10000, others unchanged
BAll employees have salary 10000
COnly Bob and Charlie have salary 10000, Alice unchanged
DNo salaries changed
Attempts:
2 left
💡 Hint

Think about what happens if you don't specify a WHERE clause in an UPDATE statement.

🧠 Conceptual
intermediate
1:30remaining
Why is running UPDATE without WHERE dangerous?

Which of the following best explains the danger of running an UPDATE statement without a WHERE clause?

AIt updates all rows, possibly overwriting data unintentionally
BIt causes a syntax error and the query fails
CIt only updates the first row and ignores the rest
DIt locks the table permanently
Attempts:
2 left
💡 Hint

Think about what happens when no filter is applied to an update.

📝 Syntax
advanced
2:00remaining
Which UPDATE statement will update only Bob's salary to 8000?

Given the Employees table, select the correct UPDATE statement that changes only Bob's salary to 8000.

AUPDATE Employees WHERE name = 'Bob' SET salary = 8000;
BUPDATE Employees SET salary = 8000;
CUPDATE Employees SET salary = 8000 WHERE id;
DUPDATE Employees SET salary = 8000 WHERE name = 'Bob';
Attempts:
2 left
💡 Hint

Remember the correct order of clauses in an UPDATE statement.

query_result
advanced
1:30remaining
What happens if you run UPDATE without WHERE on a table with 0 rows?

Consider an empty table Products with columns id and price. What is the result of running:

UPDATE Products SET price = 10;

What will be the state of the table after this query?

AThe table remains empty with 0 rows
BAll rows have price set to 10
CThe table is deleted
DSyntax error occurs
Attempts:
2 left
💡 Hint

Think about how UPDATE affects rows when there are none.

🔧 Debug
expert
2:30remaining
Why did this UPDATE without WHERE cause data loss?

A developer ran this query:

UPDATE Orders SET status = 'shipped';

They intended to update only orders with id > 100. What happened and why?

AThe query failed due to missing WHERE clause
BOnly orders with id > 100 were updated automatically
CAll orders had their status changed to 'shipped' because no WHERE clause was used
DOnly the first order was updated
Attempts:
2 left
💡 Hint

Recall what happens when UPDATE is run without a filter.