Reputation: 11571
I use below query to analyze usage of index in SQL Server.
SELECT *
FROM sys.dm_db_index_usage_stats A
WHERE A.database_id = DB_ID()
How can reset all data from this system table?
Upvotes: 8
Views: 14898
Reputation: 60642
Like mentioned, you cannot truly reset it without restarting the SQL Server.
BUT
Why do you want to reset it? Probably because you have made changes to your indexes and simply want to see how the usage has changed, am I right?
In this case you can hardcode the existing values into your query and subtract it to get new stats from this point.
By "hardcoding" I mean joining with a VALUES
pseudo-table, something like this
--your SELECT goes here
--your FROM goes here
--add this JOIN
JOIN ( VALUES('IX_index1', 2412727),
('IX_index2', 1630517),
('IX_index3', 514129)) o(name, seeks) ON o.name=indexes.name
-- rest of your query
Now you can add this to your SELECT to get the difference:
SELECT dm_db_index_usage_stats.user_seeks - o.seeks AS newseeks
So in a nutshell:
dm_db_index_usage_stats
Upvotes: 2
Reputation: 77876
What do you mean by reset
.. do you want to reset the index usage statistics in the table?
Taken from Here
Usage statistics: These are found in sys.dm_db_index_usage_stats. Index usage statistics keep track of things like seeks and scans from SELECT queries. They are not persisted and get reset on restart of sql server. These statistics also get reset if the underlying index is rebuilt "ALTER INDEX ... REBUILD", but not with "ALTER INDEX ... REORG"
As said, you can't reset it manually. Take a look at this post which certainly says the same
Upvotes: 12