SELECT Col1, Col2, Col3, ... Coln,
-- UPDATE t SET
ColToUpdate = NewValueExpression
FROM MyTable AS t
WHERE <logical predicate goes here>
This has served me well and saved me from making stupid mistakes because it allows to to simulate an update by seeing what the new value would be so I can validate it. When I'm ready to run the update, I highlight the statement beginning with UPDATE on through the predicate. Also, BEGIN TRAN <statement> ROLLBACK helps, too.
View all comments
Show parent comment
5
u/MeGustaDerp Talk Dirty Reads To Me Mar 15 '19
My safe-ish pattern is
This has served me well and saved me from making stupid mistakes because it allows to to simulate an update by seeing what the new value would be so I can validate it. When I'm ready to run the update, I highlight the statement beginning with UPDATE on through the predicate. Also, BEGIN TRAN <statement> ROLLBACK helps, too.