T-SQL – syntactic sugar for updating current row in cursor

I am not a big fan of cursors, however for time to time I have to write one. In my case cursor usually is responsible for some complicated updates. Until yesterday I’ve been writing my update statements within the cursor the standard way

There is nothing wrong with that, however we can do the same thing using specialized syntax – current of keyword(s)

The entire cursor statement then looks that way

T-SQL – syntactic sugar for updating current row in cursor

T-SQL – executing query multiple times

For time to time during my everyday work I have to do some SQL query optimization. The simplest way of measuring whether my changes improved the performance or not, is simply measure the execution time of given query (I know that this is not the best way of doing that, but let’s leave aside execution plans for now). However measuring time of single executin is not very meaningfull. Thats why I like execute query multiple times by using this simple trick

executing query multiple times
and then calculate an average time of execution by dividing the total time by execution count. As You can see, all You have to do is to specify execution count after the GO statment. Despite the fact that Management Studio indicates that there is an error in the SQL, this is perfectly valid code. Of course You should hide execution results in order to measure only the time of execution, not the time of rendering data. To do that, right click on query window and choose “Query Options…”
queryoptions
then select “Results” node and check “Discard results after execution”
queryoptionshighlighted

T-SQL – executing query multiple times