MS SQL Server 2008 如何知道表/存储过程是否正在使用?

发布于 2024-11-07 14:23:37 字数 208 浏览 0 评论 0原文

有什么方法可以确定任何项目是否正在使用任何表? 当然,问题是表何时是只读的;否则,我可以看到 新插入的行。同样的问题也适用于存储过程。 SQL Server Profiler 可能会对 SP 有帮助,但不确定表。 但我不想坐下来观察 SQL Server Profiler。我希望得到一种通知。 所以基本上,我想设置一个触发器或其他东西,如果表被命中,则读取 它通知我。

感谢您的帮助

Is there any way to determine if any table is in use or not by any project?
Of course question would be when table is only read-only; otherwise, I could see from
new inserted rows. Same question is for a stored procedure. SQL Server Profiler should probably help for SP, not sure about table.
But I don't want to sit and observe SQL Server Profiler. I wish to have a kind of notification.
So basically, I would like to set up a trigger or something, if table gets hit, read then
it notifies me.

Thanks for your help

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

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

发布评论

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

评论(2

扛刀软妹 2024-11-14 14:23:37

如果没有某种形式的提前规划,我相信答案是“不,你无法 100% 准确地确定使用情况”。

  • 如果您检查代码以识别所有引用对象,那么您总是可能会误读、误解或只是错过了某些内容。 (边缘情况:维护例程、管理员脚本、忘记的遗留代码)
  • 如果您观​​察 T 时间段内数据库上的所有活动,则总有一些进程在该时间段内没有运行。 (边缘情况:年度流程、灾难恢复例程)
  • 上述情况的交集,可能存在由用户或管理员执行的临时活动,这些活动没有记录和/或很少执行。

关键是,SQL Server 根本无法知道此类操作和可能会发生活动。您应该能够挑选出 90%、98% 或 99.9% 的所有数据库活动,但如果您需要 100% 保证表 dbo.LegacyDump 是完全不相关的垃圾,而无需参与原始设计和实施(以及完全回忆)你无法达到 100%。

当你到达这一点时,最好的选择是提出风险评估(如果我们删除该表,情况会多么糟糕),一个应急计划(如果结果证明我们不应该删除该表该怎么办)和文档(这样您或任何人都可以清楚地回忆起当发现您杀死了计算 C 级年度奖金的系统时所做的决定。)

Without some form of planning ahead, I believe the answer is "No, you can't determine usage with 100% accurarcy".

  • If you reviewed the code to identify all reference objects, there could always be something you misread, misinterpreted, or just plain missed. (Edge cases: Maintenance routines, administrator scripts, forgotten legacy code)
  • If you observed all activity on the database for T period of time, there could always be some process that did not happen to run during that period of time. (Edge cases: annual processes, disaster recovery routines)
  • An intersection of the above, there might be ad hoc activities performed by users or administrators that are undocumented and/or very infrequently performed

The point is, SQL Server simply cannot know that such actions and activities might occur. You should be able to pick out 90%, 98%, or maybe 99.9% of all database activities, but if you need that 100% assurance that table dbo.LegacyDump is flat-out irrelevant junk, without having been in on the original design and implementation (and having total recall) you just can't get to 100%.

When you get to that point, your best bet is to come up with a risk assessment (how bad might it be if we drop the table), a contingency plan (what to do if it turned out we should not have dropped that table), and documentation (so you or whoever can clearly recall the decisions made when it is found out you killed the system that calculates the C-level annual bonuses.)

一口甜 2024-11-14 14:23:37

尝试使用存储过程 sp_who2

链接:http://sqlserverplanet.com/dba/using-sp_who2/

Try using the stored procedure sp_who2

Link : http://sqlserverplanet.com/dba/using-sp_who2/

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