推荐优秀的SQL脚本调试工具Embarcadero DBArtisan 可以调试SQL Server 2000/2005 SQL调试工具汇总
调试SQL语句是经常会碰到的需求,常常为了查找报表的数据是否正确,SQL脚本为什么取不到预想中的数据,一般都可以通过调试SQL语句来解决问题,找到原因。问题不一定是系统的Bug,可能是设置不正确,可能是数据之间没有关联。
看到园子里的一篇文章"介绍一款替代SSMS的sqlserver管理工具 toad for sqlserver5.7”,这个工具我最喜欢的功能当属SQL语句调试,其它的功能,SSMS可以做到。SSMS对于SQL Server 2000/2005,无法进行脚本调试。
除了Toad for SQLServer可以解决问题外,我这里推荐Embarcadero DBArtisan,界面如下图所示
界面中看到的,是在修复ERP的报表数据,更新当前正在验货的数据(采购验货,抽查验货,生产验货)到物料主文件中。
程序安装完成后,打开它,它会枚举当前局域网中的SQL Server实例,选择需要的实例,打开一个脚本窗口,复制SQL语句片段到窗口中,再按Debgu窗口,即可开始调试。
调试问题时,可以在Watch窗口中看到被监视的变量的值,也可以把鼠标旋停在变量上查看它当前的值。
写到这里,突然想到找一下市面上能看到的所有的SQL Debugger,以方便查找。经过努力的查找,又发现了工具
Aqua Data Studio可以Step Into,Step Over存储过程和脚本片段。官网上有一段文字介绍,我把它复制到下面来
Debug AquaScripts within the Editor: Just like Aqua Data Studio's DB2, MS SQL Server, Oracle and Sybase SQL debuggers, AquaScripts can be stepped through during execution to examine results and debug errors. Functions can be evaluated and parameters entered as the debugging process continues. Breakpoints can be set and used to pause execution to examine values and parameters. The debugger highlights the breakpoints, indicates which one currently pauses the execution and sets bookmarks in the navigation bar so that they can be viewed quickly when there are multiple pages worth of lines to debug.
- Toggle a break point in the script body. A user can set a break point at any line in the source code in order to run it up to this line.
- Running the script until the break point with parameters provided by the user. The execution can be stopped at any time using the stop button. Output messages for the execution can be viewed in the Console tab.
- "Step Into","Step Over" and "Step Return" buttons allow the user to move through and execute functional blocks of the code.
- Stack, Global Scope and Local Scope can be viewed in the Debug tab.
- The user can enter variables and view their values during the execution in the Variables tab.
- The user can enter expressions and see their values in the Watches tab.
Debug AquaScripts within a Web Browser: When debugging in browser, the built-in HTTP server will provide an interface in a tab document within ADStudio. The interface will display the HTTP requests processed. The HTTP requests include which scripts that are executed, with the parameter name value pairs that are passed to the executing script.
片段语句functional blocks of the code,可以通过此工具调试。非常抱歉,至今没有在网内的网站上找到相关的下载和破解工具,无法截图以证实它所说的功能。
再来看看每天编程用到的Visual Studio 2010。在VS2003时,它就可以做到连接到SQL Server中,调试存储过程。对于片段SQL语句,可以简单的封装成存储过程,再通过VS2003的强大调试功能实现脚本追踪。
时间一下子就来到了2013年,10年前(2012)的技术到今天已经有了质的提升。SQL Server 2005引入了CLR,可以用熟悉的.NET语言编写SQL Server Object,通常是Function,Procedure,也可以定义类型,比如纬度,货币(数量和币种),复数。打开服务器管理器,选择SQL实例,勾选Application Debugging,然后选中需要调试的存储过程,填入值,即可开始追踪过程。要注意使用Windows信任连接方式,否则会报错
好了,这一下子又多出了5个同系列的SQL调试工具。从VS2003到VS2012,一共是五个出自微软的SQL调试工具。
如果把SQL Server Management Studio 也算上,从SQL Server 2008, SQL Server 2008 R2, SQL Server 2012,一共有三个同系列的SQL调试工具。这样一算,就有8个出自微软的SQL工具,可以用来调试SQL脚本。
总结一下可以调试SQL语句的工具
- Toad for SQLServer
- Embarcadero DBArtisan
- Microsoft Visual Studio 2003-2012
- SQL Server Management Studio 2008-2012