Bird
Raised Fist0
SQLquery~10 mins

UPDATE multiple columns in SQL - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - UPDATE multiple columns
Start UPDATE statement
↓
Specify table to update
↓
Set new values for multiple columns
↓
Apply WHERE condition to select rows
↓
Execute update on selected rows
↓
Finish and return number of rows updated
The UPDATE statement changes values in multiple columns for rows that meet the WHERE condition.
Execution Sample
SQL
UPDATE employees
SET salary = salary * 1.1, department = 'Sales'
WHERE department = 'Marketing';
This query increases salary by 10% and changes department to 'Sales' for employees in 'Marketing'.
Execution Table
StepActionRow IDOld salaryOld departmentNew salaryNew departmentCondition MetResult
1Check row10150000Marketing55000SalesYesUpdate applied
2Check row10260000Sales60000SalesNoNo update
3Check row10355000Marketing60500SalesYesUpdate applied
4Check row10470000HR70000HRNoNo update
5Finish------2 rows updated
💡 All rows checked; only rows with department 'Marketing' updated.
Variable Tracker
VariableStartAfter Row 101After Row 102After Row 103After Row 104Final
salary_101500005500055000550005500055000
department_101MarketingSalesSalesSalesSalesSales
salary_102600006000060000600006000060000
department_102SalesSalesSalesSalesSalesSales
salary_103550005500055000605006050060500
department_103MarketingMarketingMarketingSalesSalesSales
salary_104700007000070000700007000070000
department_104HRHRHRHRHRHR
Key Moments - 2 Insights
Why are only some rows updated and not all?
Only rows where the WHERE condition is true (department = 'Marketing') are updated, as shown in execution_table rows 1 and 3.
Does the UPDATE change columns not listed in SET?
No, only columns specified in SET are changed. Other columns keep their original values, as seen in rows 2 and 4 where no update occurs.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the new salary of row 103 after the update?
A60500
B55000
C60000
D70000
💡 Hint
Check the 'New salary' column for row 103 in the execution_table.
At which step does the condition 'department = Marketing' become false?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the 'Condition Met' column in execution_table for each step.
If the WHERE clause was removed, how would the execution table change?
AOnly rows with salary > 60000 would update
BNo rows would be updated
CAll rows would be updated
DOnly rows with department 'Sales' would update
💡 Hint
Without WHERE, UPDATE applies to all rows, so all would show 'Update applied' in the result.
Concept Snapshot
UPDATE multiple columns syntax:
UPDATE table_name
SET column1 = value1, column2 = value2
WHERE condition;
Only rows matching WHERE are updated.
Columns not listed remain unchanged.
Full Transcript
The UPDATE statement changes values in multiple columns for rows that meet the WHERE condition. In the example, employees in the Marketing department have their salary increased by 10% and their department changed to Sales. The execution table shows each row checked, whether it meets the condition, and if it is updated. Only rows 101 and 103 meet the condition and are updated. The variable tracker shows how salary and department values change step-by-step. Key moments clarify why only some rows update and that only specified columns change. The quiz tests understanding of the updated values, condition checks, and effects of removing the WHERE clause.

Practice

(1/5)
1. What does the SQL UPDATE statement do when you specify multiple columns in the SET clause?
easy
A. It deletes the rows that match the condition.
B. It only updates the first column listed and ignores the rest.
C. It creates new rows with the specified column values.
D. It changes the values of all specified columns in the selected rows.

Solution

  1. Step 1: Understand the UPDATE statement

    The UPDATE statement modifies existing rows in a table.
  2. Step 2: Effect of multiple columns in SET clause

    When multiple columns are listed in SET, all those columns are updated in the rows that match the WHERE condition.
  3. Final Answer:

    It changes the values of all specified columns in the selected rows. -> Option D
  4. Quick Check:

    UPDATE with multiple columns updates all listed columns [OK]
Hint: SET updates all listed columns together [OK]
Common Mistakes:
  • Thinking UPDATE adds new rows
  • Believing UPDATE deletes rows
  • Assuming only first column updates
2. Which of the following is the correct syntax to update two columns, price and stock, in a table named products?
easy
A. UPDATE products SET price = 10, stock = 50 WHERE id = 1;
B. UPDATE products (price = 10, stock = 50) WHERE id = 1;
C. UPDATE products SET (price, stock) = (10, 50) WHERE id = 1;
D. UPDATE products WHERE id = 1 SET price = 10, stock = 50;

Solution

  1. Step 1: Recall correct UPDATE syntax

    The correct syntax is UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;
  2. Step 2: Check each option

    UPDATE products SET price = 10, stock = 50 WHERE id = 1; matches the correct syntax exactly. The other options have syntax errors.
  3. Final Answer:

    UPDATE products SET price = 10, stock = 50 WHERE id = 1; -> Option A
  4. Quick Check:

    SET column = value pairs separated by commas [OK]
Hint: Use SET column=value, column=value syntax [OK]
Common Mistakes:
  • Using parentheses incorrectly in SET clause
  • Placing WHERE before SET
  • Missing commas between column assignments
3. Given the table employees with columns salary and bonus, what will be the result of this query?
UPDATE employees SET salary = salary + 1000, bonus = 500 WHERE department = 'Sales';
medium
A. All employees get salary and bonus updated regardless of department.
B. Only the salary of Sales employees increases; bonus remains unchanged.
C. All employees in Sales get their salary increased by 1000 and bonus set to 500.
D. Syntax error because multiple columns cannot be updated together.

Solution

  1. Step 1: Understand the WHERE clause effect

    The WHERE clause limits updates to rows where department = 'Sales'.
  2. Step 2: Analyze SET clause changes

    Salary increases by 1000 and bonus is set to 500 for those rows only.
  3. Final Answer:

    All employees in Sales get their salary increased by 1000 and bonus set to 500. -> Option C
  4. Quick Check:

    WHERE filters rows; SET updates all listed columns [OK]
Hint: WHERE limits rows; SET updates all columns listed [OK]
Common Mistakes:
  • Ignoring WHERE and updating all rows
  • Thinking bonus stays unchanged
  • Believing multiple columns update causes error
4. Identify the error in this SQL statement:
UPDATE orders SET status = 'Shipped' stock = 0 WHERE order_id = 123;
medium
A. WHERE clause should come before SET clause.
B. Missing comma between column assignments in SET clause.
C. Incorrect table name used.
D. Quotes around 'Shipped' should be double quotes.

Solution

  1. Step 1: Check SET clause syntax

    Multiple columns must be separated by commas in SET clause.
  2. Step 2: Identify missing comma

    Between status = 'Shipped' and stock = 0, a comma is missing.
  3. Final Answer:

    Missing comma between column assignments in SET clause. -> Option B
  4. Quick Check:

    Separate columns with commas in SET [OK]
Hint: Put commas between each column=value pair [OK]
Common Mistakes:
  • Omitting commas between columns
  • Placing WHERE before SET
  • Using wrong quotes for strings
5. You want to update the price and discount columns in the products table only for items where category is 'Electronics' and current stock is less than 10. Which query correctly does this?
hard
A. UPDATE products SET price = price * 0.9, discount = 10 WHERE category = 'Electronics' AND stock < 10;
B. UPDATE products SET price = price * 0.9, discount = 10 WHERE category = 'Electronics' OR stock < 10;
C. UPDATE products SET price = price * 0.9 discount = 10 WHERE category = 'Electronics' AND stock < 10;
D. UPDATE products SET price = price * 0.9, discount = 10 WHERE category = 'Electronics' AND stock > 10;

Solution

  1. Step 1: Understand the condition requirements

    We want to update only rows where category is 'Electronics' AND stock is less than 10.
  2. Step 2: Check each option's WHERE clause and syntax

    UPDATE products SET price = price * 0.9, discount = 10 WHERE category = 'Electronics' AND stock < 10; uses AND with correct conditions and proper syntax. UPDATE products SET price = price * 0.9, discount = 10 WHERE category = 'Electronics' OR stock < 10; uses OR, which updates more rows. UPDATE products SET price = price * 0.9 discount = 10 WHERE category = 'Electronics' AND stock < 10; misses a comma between assignments. UPDATE products SET price = price * 0.9, discount = 10 WHERE category = 'Electronics' AND stock > 10; uses stock > 10, which is incorrect.
  3. Final Answer:

    UPDATE products SET price = price * 0.9, discount = 10 WHERE category = 'Electronics' AND stock < 10; -> Option A
  4. Quick Check:

    Use AND for combined conditions and commas between columns [OK]
Hint: Use AND for all conditions; separate columns with commas [OK]
Common Mistakes:
  • Using OR instead of AND in WHERE
  • Missing commas between columns
  • Wrong comparison operators 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