In this tip we look at code you can use to convert an integer date into a datetime format. This is an issue you will face when working the history data for SQL Server Agent Jobs.
Introduction TOP is one of the many syntactical operators available in T-SQL and at a first view, it could seem very simple and not particularly interesting. According to the official documentation, it “limits the rows returned in a query result set to a specified number of rows or percentage of rows”. The following is the […]
In this tip we look at how to use Common Table Expressions CTE in SQL Server including the syntax, use cases, using more than 1 CTE at the same time and recursive CTEs with a parameter.
In my T-SQL code I always use set based operations. I have been told these types of operations are what SQL Server is designed to process and it should be quicker than serial processing. I know cursors exist but I am not sure how to use them. Can you provide some cursor examples? Can you give any guidance on when to use cursors?
When it detects a deadlock, SQL Server will, by default, pick the process the has the lowest cost to rollback. This can present a potential issue if the process is a business critical process. The DEADLOCK_PRIORITY allows us to have a bit of control over whether or not a process is chosen as the victim.
On my machine, code that calls SYSDATETIME() 10 million times in a loop takes about 11.6 seconds to execute, while with SYSUTCDATETIME() it takes 4.3 seconds. Why is SYSUTCDATETIME() so much faster than SYSDATETIME()?