0
0
SQLquery~10 mins

UPDATE with expressions in SQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - UPDATE with expressions
Start UPDATE
Identify rows to update
Calculate new values using expressions
Apply new values to rows
Finish UPDATE
The UPDATE command finds rows to change, calculates new values using expressions, then applies these new values to the rows.
Execution Sample
SQL
UPDATE employees
SET salary = salary * 1.1
WHERE department = 'Sales';
This increases salary by 10% for employees in the Sales department.
Execution Table
StepRow IDOld salaryCondition (department='Sales')Expression evaluationNew salaryAction
110150000True50000 * 1.1 = 5500055000Update salary
210260000FalseSkip60000No change
310355000True55000 * 1.1 = 6050060500Update salary
410470000FalseSkip70000No change
510548000True48000 * 1.1 = 5280052800Update salary
6-----End of rows
💡 All rows processed; only rows with department 'Sales' updated.
Variable Tracker
Row IDsalary (start)salary (after update)
1015000055000
1026000060000
1035500060500
1047000070000
1054800052800
Key Moments - 2 Insights
Why are some salaries not changed even though the UPDATE runs on the whole table?
Only rows where the condition (department='Sales') is true get updated, as shown in execution_table rows 2 and 4 where condition is false and action is 'No change'.
How is the new salary calculated for each row?
The new salary is computed by multiplying the old salary by 1.1, as shown in the 'Expression evaluation' column in the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the new salary for Row ID 103 after the update?
A55000
B60500
C60000
D6050
💡 Hint
Check the 'New salary' column for Row ID 103 in the execution_table.
At which step does the condition department='Sales' evaluate to false?
AStep 2
BStep 1
CStep 3
DStep 5
💡 Hint
Look at the 'Condition' column in the execution_table for each step.
If the expression changed to salary = salary + 500, what would be the new salary for Row ID 105?
A48500
B53000
C53300
D52800
💡 Hint
Add 500 to the old salary 48000 from variable_tracker for Row ID 105.
Concept Snapshot
UPDATE table_name
SET column = expression
WHERE condition;

- Finds rows matching condition
- Calculates new values using expressions
- Updates rows with new values

Expressions can use old column values.
Full Transcript
The UPDATE statement changes data in a table. It first finds rows that match a condition. Then it calculates new values using expressions, often involving old column values. Finally, it updates those rows with the new values. For example, increasing salary by 10% for employees in Sales updates only those rows where department is 'Sales'. The execution table shows each row's old salary, whether it meets the condition, the calculation done, and the new salary applied. Rows not matching the condition remain unchanged. This step-by-step process helps understand how UPDATE with expressions works.