I'm trying to get a list of unused procedures across the whole SQL server. I've accomplished getting a list of ALL procedures and now I'm using the following script to identify which procedures have been used.
DECLARE @command varchar(1000)
SELECT @command =
'USE [?] SELECT
qt.text AS "SP Name",
qs.execution_count AS "Execution Count",
qs.max_logical_reads,
qs.max_logical_writes,
qs.creation_time,
DB_NAME() as DatabaseName,
DATEDIFF(Minute, qs.creation_time, GetDate()) AS "Age in Cache"
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS qt
ORDER BY qt.text DESC'
EXEC sp_MSforeachdb @command
I'm aware that this will only show procedures which have been used post restart. The data seems to work somewhat - however; the issue i'm having is that it seems to show the WHOLE procedures text IE:
CREATE PROCEDURE dbo.proc_MSS_PropagationGetQueryServers AS
DECLARE @Temp table( ServerID int, SearchServerName nvarchar(31), IndexDirectory nvarchar(260),
MachineStatus int, LastPropagationTime datetime,
PropagationStatus int ) INSERT INTO @Temp
SELECT SearchServerID, SearchServerName,
IndexDirectory, MachineStatus, LastPropagationTime, 1 AS PropagationStatus FROM
dbo.MSSPropagationSearchServerTable UPDATE @Temp
SET PropagationStatus = 0 WHERE NOT EXISTS (SELECT * FROM dbo.MSSPropagationSearchServerReady AS R WHERE ServerID = R.SearchServerID) AND (1 < DATEDIFF(m, LastPropagationTime, GETUTCDATE()) OR 30 < DATEDIFF(s, LastPropagationTime, GETUTCDATE())) CREATE TABLE #UnresponsiveQueryServers (
ServerID int ) INSERT #UnresponsiveQueryServers EXEC
dbo.proc_MSS_PropagationGetUnresponsiveQueryServers UPDATE
@Temp SET PropagationStatus = 3 WHERE
ServerID IN ( SELECT ServerID FROM #UnresponsiveQueryServers )
UPDATE @Temp SET PropagationStatus = 2
WHERE MachineStatus = 0 OR MachineStatus = 1 OR
MachineStatus = 2 SELECT SearchServerName,
IndexDirectory, MachineStatus, PropagationStatus
FROM @Temp
I just want the name of the procedure itself. So in this case proc_MSS_PropagationGetQueryServers
Anyone able to help on this?