0
0
SQLquery~10 mins

Why UPDATE needs caution in SQL - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to update the salary of employees in the 'employees' table.

SQL
UPDATE employees SET salary = salary [1] 1000 WHERE department = 'Sales';
Drag options to blanks, or click blank then click option'
A+
B/
C*
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' will decrease the salary instead of increasing it.
Using '*' or '/' will multiply or divide the salary, which is not intended here.
2fill in blank
medium

Complete the code to update the status of orders to 'shipped' only for orders with status 'pending'.

SQL
UPDATE orders SET status = 'shipped' WHERE status [1] 'pending';
Drag options to blanks, or click blank then click option'
A>
B=
C!=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' will update orders that are not pending, which is incorrect.
Using '>' or '<' does not make sense for string comparison here.
3fill in blank
hard

Fix the error in the UPDATE statement that tries to set all product prices to 0 but accidentally omits the WHERE clause.

SQL
UPDATE products SET price = [1];
Drag options to blanks, or click blank then click option'
ANULL
B''
C0
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using NULL or empty string may cause errors or unexpected results.
Forgetting the WHERE clause can update all rows unintentionally.
4fill in blank
hard

Fill both blanks to update the 'quantity' by subtracting 1 only for items where quantity is greater than 0.

SQL
UPDATE inventory SET quantity = quantity [1] 1 WHERE quantity [2] 0;
Drag options to blanks, or click blank then click option'
A-
B+
C>
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Adding 1 instead of subtracting changes the quantity incorrectly.
Using '<=' allows zero or negative quantities, which may be invalid.
5fill in blank
hard

Fill all three blanks to update the 'status' to 'inactive' and set 'last_updated' to current date only for users with 'active' status and last login before 2023-01-01.

SQL
UPDATE users SET status = [1], last_updated = [2] WHERE status = [3] AND last_login < '2023-01-01';
Drag options to blanks, or click blank then click option'
A'inactive'
BCURRENT_DATE
C'active'
D'2023-01-01'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong status values or missing quotes causes errors.
Not filtering by status or last_login can update unintended users.