开发者

MS SQL Server 2008 How can I know whether table/Stored Procedure is in use or not?

开发者 https://www.devze.com 2023-03-06 06:40 出处:网络
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

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 shou开发者_开发知识库ld 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


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.)


Try using the stored procedure sp_who2

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

0

精彩评论

暂无评论...
验证码 换一张
取 消