存储过程上次访问时间?

发布于 2024-08-23 04:07:14 字数 222 浏览 3 评论 0原文

是否可以找出上次访问存储过程的时间?

我尝试了以下操作:

SELECT * 
FROM sys.dm_db_index_usage_stats 
WHERE [database_id] = DB_ID()  
    AND [object_id] = OBJECT_ID('stored procedure name')

它返回一个空白结果集。

Is it possible to find out when a Stored Procedure was last accessed?

I tried the following:

SELECT * 
FROM sys.dm_db_index_usage_stats 
WHERE [database_id] = DB_ID()  
    AND [object_id] = OBJECT_ID('stored procedure name')

and it returns a blank resultset.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只等公子 2024-08-30 04:07:14

我相信如果存储过程仍然位于服务器上的过程缓存中,此时您可以查询 sys.dm_exec_query_stats,这是可能的。

恐怕之后你就要开始记录和追踪了。

I believe this is possible should the sproc still be in the procedure cache on the server at which point you can query sys.dm_exec_query_stats.

After that you are down to logging and tracing I'm afraid.

表情可笑 2024-08-30 04:07:14

添加日志条目作为存储过程的第一行:

insert into dbo.ProcLog (procname, date) values ('MyProc',getdate())

Add a log entry as the first line of the stored procedures:

insert into dbo.ProcLog (procname, date) values ('MyProc',getdate())
少年亿悲伤 2024-08-30 04:07:14

这是可以放置在每个过程中的通用代码行,它将包含正确的过程名称,而无需对其进行硬编码。

INSERT INTO YourLog 
        (RunDate,ProcedureName,...) 
    VALUES 
        (GETDATE(),OBJECT_NAME(@@PROCID),...)

here is a generic line of code you can place in every procedure, it will include the proper procedure name, without hard coding it.

INSERT INTO YourLog 
        (RunDate,ProcedureName,...) 
    VALUES 
        (GETDATE(),OBJECT_NAME(@@PROCID),...)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文