Proqrammer
Programmer
- Sep 17, 2006
- 64
Hi there
Are there any drawbacks of adding too many indexes in a table?!
How much is too much?!
Are there any drawbacks of adding too many indexes in a table?!
How much is too much?!
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
--- sys.dm_db_index_operational_stats
declare @dbid int
select @dbid = db_id()
select objectname=object_name(s.object_id), indexname=i.name, i.index_id
, reads=range_scan_count + singleton_lookup_count
, 'leaf_writes'=leaf_insert_count+leaf_update_count+ leaf_delete_count
, 'leaf_page_splits' = leaf_allocation_count
, 'nonleaf_writes'=nonleaf_insert_count + nonleaf_update_count + nonleaf_delete_count
, 'nonleaf_page_splits' = nonleaf_allocation_count
from sys.dm_db_index_operational_stats (@dbid,NULL,NULL,NULL) s,
sys.indexes i
where objectproperty(s.object_id,'IsUserTable') = 1
and i.object_id = s.object_id
and i.index_id = s.index_id
order by reads desc, leaf_writes, nonleaf_writes
--- sys.dm_db_index_usage_stats
select objectname=object_name(s.object_id), indexname=i.name, i.index_id
,reads=user_seeks + user_scans + user_lookups
,writes = user_updates
from sys.dm_db_index_usage_stats s,
sys.indexes i
where objectproperty(s.object_id,'IsUserTable') = 1
and s.object_id = i.object_id
and i.index_id = s.index_id
and s.database_id = @dbid
order by reads desc
go
SELECT d.name as db_name, s.name as table_name,si.name as index_name,
i.index_id, si.rowcnt, i.system_scans
FROM sys.dm_db_index_usage_stats i
JOIN sys.sysobjects s
ON i.object_id = s.id
JOIN sys.sysdatabases d
ON i.database_id = d.dbid
JOIN sys.sysindexes si
ON i.object_id = si.id
WHERE i.index_id <> 1
AND d.name not in ('tempdb')
ORDER BY rowcnt desc
SELECT d.name as db_name, s.name as table_name,si.name as index_name,
i.index_id, si.rowcnt, i.system_scans
FROM sys.dm_db_index_usage_stats i
JOIN sys.sysobjects s
ON i.object_id = s.id
JOIN sys.sysdatabases d
ON i.database_id = d.dbid
JOIN sys.sysindexes si
ON i.object_id = si.id
WHERE user_seeks = 0
AND user_scans = 0
AND user_lookups = 0
AND user_updates = 0
AND i.index_id <> 1
AND d.name not in ('tempdb')
ORDER BY rowcnt desc