I could probably google this, but it seemed quirky enough that it might be worth having logged as an answer on SA.
So in development land, if you want to swap interchance the values of two variables, you need a third temp variable.
e.g.
string x = "ABC";
string y = "DEF";
string temp;
temp = x;
x = y;
y = temp;
However in a SQL Update, you can simply say
UPDATE table
SET ColumnA = ColumnB, ColumnB = ColumnA
How does this work under the hood
- Does SQL Server take a snap shot of the entire row first ?
- Does SQL Server take a snap shot of all the rows being updated in one go ?
- Does the optimizer realize that it's doing a column interchange, and make a temp variable behind the scenes?
Cheers EoinC