[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

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.
0
enrique_aeo
Asked:
enrique_aeo
3 Solutions
 
Brian CroweCommented:
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
 
Anthony PerkinsCommented:
Is there any tool or command that allows me to identify report
Short answer, no not really.
0
 
Randy Knight, MCMCommented:
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now