SQL Server Scripts

Script: Find Top 10 CPU Intensive Queries

If you want to find the top ‘n’ queries that are currently in the cache, which are consuming more CPU, then you are at the right place. sys.dm_exec_query_stats DMV contains all the information about the resource (CPU, Memory, I/O) consuming queries that are currently in the cache. We can just join the above DMV with [...]

Script: How to Identify Whether Optimizer is Reusing the Plans or Not

If you want to identify non parameterized queries that are hogging your SQL Server plan cache then you are at the right place. sys.dm_exec_query_stats DMV becomes very handy when we are looking out for statistical information related to queries. Upon executing the above DMV, we will see a lot of columns in the output, but [...]

Script: Find FillFactor of All Indexes in a Database

In our previous blog posts, we have seen how to find fragmented indexes in a database and how to defrag them by using rebuild/reorganize. While creating or rebuilding indexes, we can also provide an option called “FILLFACTOR” which is a way to tell SQL Server, how much percentage of space should be filled with data [...]

Script: How to Defragment All The Indexes In a Database

In our previous blog post, we got to know, how to find out all fragmented indexes in a database. Now we will see how to defrag indexes. According to Microsoft guidelines, based upon index fragmentation percentage, we may choose to either REORGANIZE, REBUILD indexes or just ignore. Here are the MS guidelines. Let’s say N [...]

Script: Find The Fragmented Indexes In A Database

We do create indexes to improve the search performance of our queries. But over a period of time, because of DML operations (inserts/deletes/updates), the data will get spread across the disc (Physical order of pages are NOT in sequence). This is called fragmentation. Watch this video by @A_Bansal to understand index fragmentation & page splits. [...]

Script: Find Tables Without Clustered Index

Before we start fine tuning SQL Server, it is good to make sure all basic best practices are in place. One such best practice is to have a clustered index on every table in the database (well, not always but most of the times, having clustered index per table yields better performance, especially if you [...]


Go to Top