tool for identify objects databse are not used

Is there any tool or command that allows me to identify report (within a period of time, for example 6 months) that no objects are used (procedures, functions, views). This in order to debug a database objects and old data.
enrique_aeoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brian CroweDatabase AdministratorCommented:
Basically you will need to query cached execution plans.

Views:

SELECT v.name [ViewName]
FROM sys.views v
WHERE v.is_ms_shipped = 0

EXCEPT SELECT o.Name [ViewName]
FROM master.sys.dm_exec_cached_plans p
CROSS APPLY sys.dm_exec_sql_text(p.plan_handle) t
INNER JOIN sys.objects o ON t.objectid = o.object_id
WHERE t.dbid = DB_ID()
GO

Open in new window


Stored Procedures:

SELECT p.name AS 'SP Name'        -- Get list of all SPs in the current database
    FROM sys.procedures AS p
    WHERE p.is_ms_shipped = 0
    
    EXCEPT
    
    SELECT p.name AS 'SP Name'        -- Get list of all SPs from the current database 
    FROM sys.procedures AS p          -- that are in the procedure cache
    INNER JOIN sys.dm_exec_procedure_stats AS qs
    ON p.object_id = qs.object_id
    WHERE p.is_ms_shipped = 0;

Open in new window


Functions:

SELECT o.name AS 'SP Name'        -- Get list of all SPs in the current database
FROM sys.objects AS o
WHERE o.type IN ('FN', 'IF', 'TF')
    
EXCEPT
    
SELECT o.name AS 'SP Name'        -- Get list of all SPs from the current database 
FROM sys.objects AS o          -- that are in the procedure cache
INNER JOIN sys.dm_exec_procedure_stats AS qs
ON o.object_id = qs.object_id
WHERE o.type IN ('FN', 'IF', 'TF');

Open in new window


I'm sure these could be rolled up into a single query with a type tag of some kind if you wanted.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anthony PerkinsCommented:
Is there any tool or command that allows me to identify report
Short answer, no not really.
0
Randy Knight, MCMPrincipal ConsultantCommented:
Check out sys.dm_db_index_usage_stats.  The stats in here are aggregates since the last service restart.  There are also columns which give you a timestamp for the last time an index was used.  

Something like this.

SELECT t.name AS TableName, s.*
FROM sys.dm_db_index_usage_stats s
	INNER JOIN sys.tables t ON s.object_id = t.object_id
WHERE index_id IN (0,1)
ORDER BY s.user_seeks + s.user_scans + s.user_lookups + s.user_updates

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.