Category: SQL Server

SQL: List of tables and indexes, with associated File Group

The script within this post returns a list of all tables (along with the schema name), and indexes (where they exist), and the name of the associated file group.

This will useful to find out which objects have been assigned to the wrong file group.

I have a database with over 10 file groups, and wanted to find out why there was over 50Gb of data in the PRIMARY file group, even though there were only a couple of tables in that group. When I ran this script, I discovered there were some indexes that had been incorrectly created in the PRIMARY group!!!

SQL: Red Gate’s SQL Search

Hi. I have just downloaded Red Gate’s FREE SQL Search tool from http://www.red-gate.com/products/SQL_Search/index.htm Features: Find fragments of SQL text within stored procedures, functions, views and more Quickly navigate to objects wherever they happen to be on your servers Find all references to an object Integrates with SSMS Why use SQL Search? Impact Analysis You want […]

SQL: Median function for SQL Server

I have been using a Transact-SQL query (see Method 1 – Update entire table below) to get the Median “Order Value” for an entire list of Customers. However, due to the quantity of data, it was taking for ever.

Therefore, this morning I decided to write a SQL Server User Defined Function (see Method 2 – Function below) [1. Please ensure you test any script taken from my website on a test/development machine, before running on a production server.] to update the Median Order Value for a single Customer. I then used a UPDATE query to update all of the customers. This took a lot less time to process πŸ™‚