Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4625390
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:15:55+00:00 2026-05-22T03:15:55+00:00

I heard in Microsoft SQL Server there are multiple ways to find worst stored

  • 0

I heard in Microsoft SQL Server there are multiple ways to find “worst” stored procedures: by number of executions, by CPU worker time, by queue wait time etc.

I am looking for a way to find worst (slowest / most used) UDFs — is there a DMV query for that?

For example this query from Five DMV Queries That Will Make You a Superhero returns top 25 cached SPs by total worker time, which effectively means most expensive stored procedures for CPU pressure.

How do I write something like this for UDFs?

SELECT TOP(25) p.name AS [SP Name], qs.total_worker_time AS [TotalWorkerTime], 
qs.total_worker_time/qs.execution_count AS [AvgWorkerTime], qs.execution_count, 
ISNULL(qs.execution_count/DATEDIFF(Second, qs.cached_time, GETDATE()), 0) AS [Calls/Second],
qs.total_elapsed_time, qs.total_elapsed_time/qs.execution_count 
AS [avg_elapsed_time], qs.cached_time
FROM sys.procedures AS p
INNER JOIN sys.dm_exec_procedure_stats AS qs
ON p.[object_id] = qs.[object_id]
WHERE qs.database_id = DB_ID()
ORDER BY qs.total_worker_time DESC OPTION (RECOMPILE);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:15:56+00:00Added an answer on May 22, 2026 at 3:15 am

    Try this.

    • changing sys.procedures to sys.sql_modules
    • add further join to sys.objects
    • filter by sys.objects.type IN ('IF', 'TF', 'FN')

    The code above restricts to stored procs only

    Note: there is no “sys.functions”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I heard on the grapevine that Microsoft will be releasing SQL Server 2008 R2
I'm trying to do quite a lot of querying against a Microsoft SQL Server
Hi I have access to SQL Server at work and I've heard some interesting
I have been working with Microsoft SQL Server since 6.5 along with other database
I'm using ColdFusion with Microsoft SQL Server 2005 and on occasion I get this
I have heard from some of the microsoft connect blogs that Geneva Server works
I am using Microsoft SQL 2005 server. I have created several SP and Functions
I heard Microsoft allows use of commercially available Office UI controls, with the exception
I heard that microsoft does not recommend using DataSets and DataTables in new projects.
I heard somewhere that NHibernate for .NET will stop development because microsoft developed the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.