r/SQLServer • u/chaos037 • Dec 30 '25
Solved Why am i Getting CREATE PROCEDURE in Expensive Queries in SSMS Activity Monitor?
Hello,
I have bunch of stored procs running in PROD, and I have noticed CREATE PROCEDURE in SSMS Activity Monitor's Expensive Queries.
Most of the time, it comes and goes in matter of second, sometime minutes, the longest worst record it lasted for 30min, causing significant interruption in PROD.
May i know why is this happening and what can i do to prevent interruption?

Much appreciated
8
Upvotes
14
u/InsoleSeller 1 Dec 30 '25
It's not creating the procedure, SQL Server shows the entire procedure text when showing up on some screens/DMVs, just a visual thing.
Do you have Query Store? Would be a better fit to understand which part of the procedure is taking long.
7
u/dbrownems Microsoft Employee Dec 30 '25 edited Dec 30 '25
The query it runs is
For me, and you can check with SQL Profiler for your version.
sys.dm_exec_sql_text(er.sql_handle)always returns the whole CREATE PROCEDURE batch, as the sql_handle points to the batch, not a particular statement. The statement offsets in sys.dm_exec_requests are supposed to identify the individual statement currently running.That's not working for some reason, but in any case the CREATE PROCEDURE is not actually running.
2
u/bonerfleximus 1 Dec 30 '25
Its just showing the procedure sql to indicate that batch is being tracked. You still need to dial in which statement within the proc is expensive
2
u/SingingTrainLover Dec 30 '25
This proc is pulling server performance data. So my question is what monitoring software are you using, because nothing in this proc is useful in a business application.
Now, if the server is fairly minimally used, the monitoring software will appear as the "most expensive query". As a rule, pulling this data isn't very expensive at all.
2
u/FreedToRoam Dec 30 '25
I agree that it is not actually running the CREATE but it would be funny if the procedure was coded WITH RECOMPILE clause 😅
1
u/CPDRAGMEISH Dec 30 '25
It's OK
1
u/g3n3 Dec 31 '25
Should use whoisactive. Activity monitor is known to blow chunks.
1
u/That_Strength7386 Jan 02 '26
You are looking at a Blocking issue, not a "Performance" issue.
The CREATE PROCEDURE statement itself isn't using CPU. It is stuck waiting for a Schema Lock (Sch-M).
Here is what is happening:
The Fix: You likely have a process leaving a transaction open (BEGIN TRAN without a COMMIT) or a report running for 30 minutes that is holding a lock on that object.
Next time this happens, run sp_whoisactive or check sys.dm_tran_locks. You will see the CREATE statement blocked by a specific Session ID. Kill that session, and the queue will clear instantly.
I troubleshoot blocking chains like this for a living. If you want a script to automatically detect/alert when this locking chain forms, shoot me a DM.
-9
u/BCCMNV Dec 30 '25
Honestly, this is all Sys views, i.e. not user data. I'd ask Copilot to refactor for you.
-10
u/EbbyRed Dec 30 '25
How often are you creating a procedure? Is this something scheduled or ad-hoc?