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