最後,我發現解決方案由我自己。感謝我的友好社區。
對於真正瞭解問題的同事。請使用此方法(整個測試腳本「選擇」部分是穴):
CREATE PROCEDURE [my_dummy_sp]
@rowcount INT OUTPUT
AS
BEGIN
SELECT TOP 10 * FROM [sys].[objects];
SET @rowcount = @@ROWCOUNT;
RETURN 0;
END;
GO
DECLARE @sp_exec_stats TABLE
(
[rec_id] BIGINT IDENTITY(1, 1)
,[sp_name] NVARCHAR(256)
,[db_name] NVARCHAR(256)
,[sys_dt] DATETIMEOFFSET(7)
,[logical_reads] INT
,[physical_reads] INT
,[duration] INT
,[writes] INT
,[rowcount] INT
,[cpu_time] INT
);
DECLARE @rowcount INT;
EXECUTE [my_dummy_sp]
@rowcount = @rowcount OUTPUT;
INSERT INTO @sp_exec_stats
(
[sp_name]
,[db_name]
,[sys_dt]
,[logical_reads]
,[physical_reads]
,[duration]
,[writes]
,[rowcount]
,[cpu_time]
)
SELECT TOP 1
[sp_name] = 'my_dummy_sp'
,[db_name] = DB_NAME()
,[sys_dt] = [last_execution_time]
,[logical_reads] = [last_logical_reads]
,[physical_reads] = [last_physical_reads]
,[duration] = [last_elapsed_time]
,[writes] = [last_logical_writes]
,[rowcount] = @rowcount
,[cpu_time] = [last_worker_time]
FROM
[sys].[dm_exec_procedure_stats]
WHERE
[object_id] = OBJECT_ID('my_dummy_sp')
ORDER BY
[last_execution_time] DESC;
DROP PROCEDURE [my_dummy_sp];
SELECT * FROM @sp_exec_stats;
的
可能重複:https://dba.stackexchange.com/questions/16493/tracking-stored-procedure-usage –
感謝downvotes,但它不是重複的。請進一步探討這個問題。 – Juozas
請提供一些示例輸入,預期輸出以及您嘗試過的任何內容。這就是我覺得它是重複的原因。 –