Stored Proc Activity-Usage

  • hi everyone, i was assigned the task of unearthing the usage of stored procedures in our database. Is there anyway i can monitor the usage of all stored procedures to see which ones are being used the most often and which ones aren't?

  • SQL Profiler is the one you can use.

  • Hi

    You can use sys.dm_exec_cached_plans to know the procs executed the most.

    Check out this query i got from the web.

    SELECT CASE when dbid = 32767

    then 'Resource'

    else DB_NAME(dbid) end [DB_NAME],

    --OBJECT_SCHEMA_NAME(objectid,dbid) AS [SCHEMA_NAME],

    OBJECT_NAME(objectid)AS [OBJECT_NAME],

    SUM(usecounts) AS [Use_Count],

    dbid,

    objectid

    FROM sys.dm_exec_cached_plans cp

    CROSS APPLY sys.dm_exec_sql_text(cp.plan_handle)

    WHERE objtype = 'Proc'

    AND UPPER(

    -- remove white space first

    REPLACE(

    REPLACE(

    REPLACE(

    REPLACE(

    REPLACE(

    REPLACE(

    REPLACE(text,' ',' '),

    ' ',' '),

    ' ',' '),

    ' ', ' '),

    ' ',' '),

    ' ',' '),

    ' ',' ')

    )

    LIKE '%CREATE PROC%' and dbid = 7

    GROUP BY dbid, objectid

    Order by sum(usecounts) desc;

    "Keep Trying"

  • If you are not calling stored procedure with schema prefix, then it is possible that it will not be picked by plan cache every time. So to use SQL profiler is more better option.

    DBDigger Microsoft Data Platform Consultancy.

  • found a few articles pertaining to monitoring stored procs using Dynamic management views (DMV) and Dynamic management functions (DMF), basically utilizes the cache to return statistics. Problem is i cant use these functions...

  • You need to use a server-side trace. You can build this manually using the T-SQL commands or you can use the SQL Profiler tool to build it for you. This article has an introduction. Don't use the Profiler GUI directly against production databases[/url], especially if they're already experiencing a stressful load.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Server-side Profiler trace will be the best option.

    check this for help...

    http://sqlserverpedia.com/wiki/Running_Traces_with_TSQL

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Sometimes, winning is not an issue but trying.
    You can check my BLOG
    [font="Arial Black"]here[/font][/url][/right]

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply