<cffunction name="getNotUsedIndex" output="No" returntype="any" description="lists any index not used since the last time SQL Server was recycled.">
<cfargument name="DBName" default="master" type="any">
<cfargument name="DBObjName" default="" type="any">
<cfset var getNotUsedIndex = "">
<cfquery name="getNotUsedIndex" datasource="yourdsn" username="youruserName" password="yourpasswd">
use #DBName#
Select object_name(i.object_id) as objName, i.name as indexName
From sys.indexes i, sys.objects o
Where i.index_id NOT IN (
Select s.index_id
From sys.dm_db_index_usage_stats s
Where s.object_id=i.object_id
and i.index_id=s.index_id
)
and o.type = 'U'
and o.object_id = i.object_id
<cfif Len(Trim(DBObjName))>
and o.object_id = object_id('#DBObjName#')
</cfif>
Order by object_name(i.object_id) asc
</cfquery>
<cfreturn getNotUsedIndex>
</cffunction>
Posted At : Mar 22, 2007 19:35 PM
| Posted By : Ed Tabara
Related Categories: ColdFusion, My Projects, cfSQLMaster, SQL
Related Categories: ColdFusion, My Projects, cfSQLMaster, SQL
So, you will get the list of indexes not used since the last time SQL Server was recycled.
| 9348 Views
| 11% / 0% Popularity
Comments
Note that this does not work for sql2000 (which sucks!).
# Posted By
tof
| Jul 16, 2007 9:29 AM