如何调试tsql存储过程?
如何调试 tsql 存储过程。我已经尝试过以下链接。
http://msdn.microsoft.com/en- us/library/ms241871(v=vs.80).aspx
但我无法达到断点。有没有更好的调试方法。我的环境是
Sql Express 2008、Visual Studio 2010
How do I debug a tsql Stored procedure. I have tried the following link.
http://msdn.microsoft.com/en-us/library/ms241871(v=vs.80).aspx
But I am unable to hit the break point. Is there a better way to debug. My environment is
Sql Express 2008, Visual Studio 2010
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现 SQL Managment studio 中的调试器不可靠,因为它非常依赖于数据库服务器上的正确权限,而这些权限并不总是可用。
我使用的一种替代方法是将存储过程转换为长查询。我首先将所有参数移至变量声明并设置它们的值。例如,以下内容
将变为
这允许我从顶部开始在存储过程中运行查询。当我向下浏览查询时,我可以通过简单地选择变量并从顶部重新运行查询来检查变量的值:
我还可以注释掉 INSERT-SELECT 语句的 INSERT 部分,以查看插入到表和表中的内容变量。
使用此方法,存储过程中的错误通常会变得非常明显。一旦查询正确运行,我只需将代码复制到我的过程中并重新编译即可。
祝你好运!
I have found the debugger in SQL Managment studio unreliable as it's so dependant on having the correct permissions on the db server which are not always available.
One alternate method I use is to convert the stored proc into a long query. I start by moving any parameteres to variable declarations and set their values. For examples the following
would become
This allows me to run the queries within the stored procedure starting from the top. As I move down through the queries, I can check the values of variables by simply selecting them and rerunning the query from the top:
I can also comment out the INSERT portion of INSERT-SELECT statements to see what is being inserted into tables and table variables.
The bug in the stored proc usually becomes quite evident using this method. Once I get the query running correctly I can simply copy the code to my proc and recompile.
Good luck!
您可以尝试
Sql Profiler
,它不允许像“此时中断”这样的经典调试,但会为您提供有关查询/SP 执行的每个步骤所发生情况的详细信息。不幸的是,微软没有为其提供
Express Edition
版本的Sql Server。但是:)有一个很好的(相对而言,因为它没有提供微软中存在的大量过滤标准)并且免费的替代方案 - SQL Server 2005/2008 Express Profiler。
You can try out
Sql Profiler
, it does not allows a classical debugging like "break at this point" but gives you an information in great detail about what is going on on each step of a query/SP execution.Unfortunately Microsoft does not provide it with
Express Edition
version of Sql Server.BUT :) There is a good (relatively because it does not provide a lot of filtering criterias which exists in Microsoft's one) and free alternative - SQL Server 2005/2008 Express Profiler.
调试存储过程。
使用一个主存储过程来控制顶层,并使用多个子存储过程逐步完成工作。
根据优化,使用执行计划、SS Profiler 和 DTA 工具。
Debug a stored procedure.
use a master stored procedure to take control on the top, and use several child stored procedures to do the job step by step.
As per the optimization, use execution plan, SS Profiler and DTA tools.