<cffunction name="getIndexStats" output="No" returntype="any" description="lists statistics for existing Indexes, ordered by user_updates.">
<cfargument name="DBName" default="master" type="any">
<cfargument name="DBObjName" default="" type="any">
<cfargument name="indexName" default="" type="any">
<cfset var getIndexStats = "">
<cfquery name="getIndexStats" datasource="yourdsn" username="youruserName" password="yourpasswd">
use #DBName#
Select s.*, db_name(s.database_id) as dbName, object_name(s.object_id) as objName, i.name as index_name
From sys.dm_db_index_usage_stats s, sys.indexes i, sys.objects o
Where i.index_id = s.index_id
and o.type = 'U'
and o.object_id = i.object_id
<cfif Len(Trim(DBObjName))>
and s.object_id = object_id('#DBObjName#')
</cfif>
<cfif Len(Trim(indexName))>
and i.name = '#indexName#'
</cfif>
Order by user_updates desc
</cfquery>
<cfreturn getIndexStats>
</cffunction>
Posted At : Mar 22, 2007 19:26 PM
| Posted By : Ed Tabara
Related Categories: ColdFusion, My Projects, cfSQLMaster, SQL
Related Categories: ColdFusion, My Projects, cfSQLMaster, SQL
This script will lists statistics for existing indexes.
| 7723 Views
| 9% / 0% Popularity
Comments