调试存储过程(以及编写易于调试的sproc)的最佳方法是什么? [英] What is the best way to debug stored procedures (and write sprocs that are easier to debug)?
问题描述
有什么好的方法可以创建可减轻调试麻烦的存储过程?还有什么工具可以用来调试存储过程?
What are good methodologies for creating sprocs that reduce the pain of debugging? And what tools are out there for debugging stored procedures?
也许最重要的是,有什么迹象可以表明错误是在存储过程中而不是在代码中发生的?我希望我在这方面不会太糟糕了。投票给以上任何一个答案。谢谢。
Perhaps most importantly, what are indications to look out for that errors are happening in a sproc and not in the code? I hope I'm not all over the board too terribly bad here. Votes for answers to any of the above. Thanks.
对于它的价值,我在.NET环境中工作,即SQL服务器。
For what it's worth, I work in a .NET environment, SQL servers.
推荐答案
在存储过程中使用的一种技术,使它们更易于调试(没有IDE或调试器)以用于SQL Server 2005过程:
One technique I use in stored procedures to make them easier to debug (without IDE or debuggers) for SQL Server 2005 procedures:
我添加了在该过程的参数列表的末尾输入一个名为@Debug = 0(默认为0 = off)的输入参数。
I add an input parameter named @Debug = 0 (defaulted to 0 = off) at the end of the parameter list for the procedure.
然后添加if(@Debug = 1 )打印'...';
I then add if (@Debug = 1) print '...';
关键时刻的代码中的语句以显示任何有用的内部值等。
statements in the code at key junctures to display any useful internal values etc.
是的,它是老派,而调试器则可以让您遍历代码,但是它对任何使用任何SQL工具的人(包括使用相同IDE进行调试的任何人)都有效。
Yes, it's "old school" and debuggers that let you "walk the code" are great - but this works for anyone from any SQL tool (including anyone debugging without your same IDE).
罗恩
这篇关于调试存储过程(以及编写易于调试的sproc)的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!