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 Prospective-Index Column(s) Selectivity Analyzer

By Jesse Roberge,

*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
Util_GetSelectivity
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.

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

Copyright:
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
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

see <http://www.fsf.org/licensing/licenses/lgpl.html> for the license text.

*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=

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

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

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

SCRIPT

The Ultimate Column Searcher

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

FORUM

computed column "Version" from table sysdatabases

computed column "Version" from table sysdatabases

BLOG

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...

FORUM

Specifiying TableNames,ColumnNames as sproc param?

Is it possible to specify TableNames, ColumnNames as stored procedure parameters for be used in a SQ...

Tags
 
Contribute

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
Editor, SQLServerCentral.com

Already a member? Jump in:

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