Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

The Ultimate Dupe Finder & Performance Test Parameter Set Researcher

By Jesse Roberge,

By Jesse Roberge -

Finds the largest dupe-sets of one or more columns of a single table or derived table.
Much simpler and much much lower overhead (1 scan total vs 3 scans per column) than Util_GetSelectivity
if you don't need the detailed selectivity analysis for indexes, and
without the dependencies on delimiter functions and a table of numbers.
Great for finding hoggy parameter combinations for performance testing queries (or parts of queries such as corellated subueries or derived tables) within stored procedures!

Required Input Parameters:
@TableName nVarChar(max), Name of the table to analyze. If you want to schema qualify, use 'schema.table'.
Can accept derived table subqueries. feed something like '(SELECT ... FROM ... JOIN ... WHERE ...) AS Table)
@ColumnName nVarChar(4000) Comma separated list of columns to analyze. 'column1' or 'column1,column2'

Optional Input Parameters:
@WhereClause nVarChar(4000)='' Analyze only a subset of a the data in a table. Omit the 'WHERE'
@Top int=25, Select @Top largest dupe sets

EXECUTE Util.Util_FindHighest 'dbo.Products', 'FK_IndustryID, FK_CategoryID'

EXECUTE Util.Util_FindHighest
(SELECT Industry.IndustryName, Category.CategoryName, Product.AddDate
FROM dbo.Product JOIN dbo.Industry ON Product.FK_IndustryID=Industry.PK_IndustryID JOIN Category ON Product.FK_CategoryID=Category.PK_CategoryID
) AS ConfigBatches
@ColumnName='IndustryName, CategoryName',

Licensed under the L-GPL - a weak copyleft license - you are permitted to use this as a component of a proprietary database and call this from proprietary software.
Copyleft lets you do anything you want except plagiarize, conceal the source, or prohibit copying & re-distribution of this script/proc.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU Lesser General Public License for more details.

see <> for the license text.


Total article views: 886 | Views in the last 30 days: 3
Related Articles

The Ultimate Prospective-Index Column(s) Selectivity Analyzer

Gets single-column and cumulative-column selectivity stats and @Top largest dupe sets for each cumul...


SQL Query of last records(timestamp) for Distinct CategoryId's in same table.

SQL Query of last records(timestamp) for Distinct CategoryId's in same table.


Not Selecting All Columns in select query

Not Selecting All Columns in select query


SSIS Licensing Question



Total SQL Analyzer Review

Often times, a DBA is asked by clients to document their entire server. This usually includes jobs, ...

performance tuning    
sql server 2005    

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones