SQL Clone
SQLServerCentral is supported by Redgate
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 Prospective-Index Column(s) Selectivity Analyzer

By Jesse Roberge,

By Jesse Roberge - YeshuaAgapao@Yahoo.com
Update - Fixed existance check for drop

Gets single-column and cumulative-column selectivity stats and @Top largest dupe sets for each cumulative column stepping for a set of one or more columns for a table.
WARNING: this proc will completely scan the @SchemaName.@TableName table three times for each column name in @ColumnName.
This requires fn_DelimitToArray. You can search the scripts for 'Delimited String Parsing Functions - Basic Set' to get the function.
fn_DelimitToArray requires a table of numbers called 'Counter'. That can be found by searching the scripts for 'Counter table (table of numbers) setter-upper for SQL Server 2005'
Update 2009-05-01: The version submitted was broken for some reason. This version also references the delimiter functions and counter tables in a centralized 'global' database.

Required Input Parameters:
@ColumnName sysname Comma separated list of columns to analyze
@TableName sysname Table that these columns belong to

Optional Input Parameters:
@SchemaName sysname='dbo' Schema that @TableName belongs to
@Top int=25 Max number of rows to return for each column stepping for the 2nd result set.

EXECUTE Util.Util_GetSelectivity @SchemaName='config', @TableName='states', @ColumnName='StateName', @Top=25

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 plagarize, conceal the source, proprietarize modifications, 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 <http://www.fsf.org/licensing/licenses/lgpl.html> for the license text.


Total article views: 2086 | Views in the last 30 days: 1
Related Articles

How to get schemaname, tablename, identity column, foreign key constraints

How to get schemaname, tablename, identity column, foreign key constraints


The Ultimate Column Searcher

Searches for columns with names containing @Colname that belong to tables with names containing @Tab...


computed column "Version" from table sysdatabases

computed column "Version" from table sysdatabases


Deactivate SQLTreeo license

Version SQLTreeo SSMS Add-in version 0.8.4 or higher. Purpose Deactivate a SQLTreeo license when you...


How to obtain the version and license for a Red Gate SQL BACKUP install

/* here is a little script I've hobbled together that I use to get version and license info for a R...