存储过程上次访问时间?
是否可以找出上次访问存储过程的时间?
我尝试了以下操作:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信如果存储过程仍然位于服务器上的过程缓存中,此时您可以查询 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.
添加日志条目作为存储过程的第一行:
Add a log entry as the first line of the stored procedures:
这是可以放置在每个过程中的通用代码行,它将包含正确的过程名称,而无需对其进行硬编码。
here is a generic line of code you can place in every procedure, it will include the proper procedure name, without hard coding it.