John Sansom – SQL Server DBA in the UK Rotating Header Image

Posts under ‘TSQL’

How much memory is each SQL Server database using?

Whilst perusing the forums over at SQL Server Central today I stumbled across an interesting question regarding how to identify how much memory is being used by SQL Server on a per database level. As you know SQL Server stores database data and index pages in memory in an area know as the Buffer Pool. [...]

SQL Snippet: Who owns that SQL Server Job?

Here is a handy T-SQL script that will list all SQL Server Agent Job owners by job. From an administration perspective, this query can come in handy when you need to ensure/validate the job owners on your server. One common mistake that I have seen is that when a user creates a new SQL Server [...]

SQL Snippet: SQL Server Wait Types

Here is a handy little SQL Snippet that will return information about those all important SQL Server Wait Types for your server. It uses the SQL Server Dynamic Management View (DMV) sys.dm_os_wait_stats in order to extrapolate the desired information. A column has also been added to provide details of the percentage of total wait time [...]

Solutions to common T-SQL problems

Some of the moderators over at the MSDN SQL Server Forums have got together and collated a reference of solutions to common T-SQL problems. As always, all quality resources get added to the SQL Server Resrouces area of this site.

Generate a random number in SQL Server

What is the best way to efficiently generate a random number in SQL Server? One of my favourite SQL Server authors, Michelle Ufford recently posted her method for generating a random number, in the post Random Number Generator in T-SQL. This got me thinking and I decided to do a little investigation of my own [...]

DMV Query to identify all active SQL Server Sessions

You may already be aware that I am a big advocate of the SQL Server Dynamic Management Views (DMV’s) and the benifits that they bring to the Database Administrator. They certainly came in handy with a requirement I had recently whereby I needed to identify the IP Address of a specific SQL Server Login and [...]

Performing fast SQL Server delete operations

There have been quite a few queries on the forums this past week with regard to performing fast delete operations on large tables and I wanted to share some of the possible solutions here with you. Fast ordered delete using a view To perform a fast ordered delete, take a look at the article  Fast [...]

How to identify the most costly SQL Server queries using DMV’s

I was investigating a performance issue recently and so thought I would share the T-SQL query that I created with you. There’s nothing new or magic here, the code snippet simply identifies the top 20 most expensive queries (currently cached) based on the cumulative CPU cost. The query returns both the SQL Text from the [...]