如何在复杂的 SQL Server 查询中找到匹配的 BEGIN END 对? [英] How to find matching BEGIN END pairs in complex SQL Server query?

查看:31
本文介绍了如何在复杂的 SQL Server 查询中找到匹配的 BEGIN END 对?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对一个巨大的存储过程进行逆向工程.里面有大量的 BEGIN END,并不是所有的都缩进正确,有很多层深,我很费时间找到哪些 BEGIN END 对彼此匹配.

I'm reverse engineering a gigantic stored procedure. There are tons of BEGIN ENDs in it, not all indented properly, many levels deep, and I am having a heck of a time finding which BEGIN END pairs match each other.

是否有一种简单的方法可以找出哪些对彼此匹配.我知道在 Visual Studio 中,您可以使用 ctr+] 从左括号跳到右括号,在 SSMS 2008 中也是如此.但我使用的是 2005.

Is there an easy way to find out which pairs match each other. I know in Visual studio you can jump from opening bracket to closing bracket with ctr+] and same thing in SSMS 2008. But I'm using 2005.

有什么想法吗?

推荐答案

在 SQL Server 2005 中,ctrl+] 仍然适用于 },它只是不适用于 BEGIN END.SQL Server 2005 不区分注释掉的括号和未注释的括号,因此我的解决方案是将所有 BEGIN 替换为 BEGIN/*{*/ 和所有 ENDEND/*}*/.

In SQL Server 2005, ctrl+] still works for }, it just doesn't work for BEGIN END. SQL Server 2005 doesn't distinguish between commented out brackets and uncommented brackets, so my solution was to replace all BEGINs with BEGIN/*{*/ and all ENDs with END/*}*/.

所以我有这样的事情:

BEGIN/*{*/

    BEGIN/*{*/

    END/*}*/

END/*}*/

这样我就可以来回跳转到配对的 BEGINEND.

With that I was able to jump back and forth to the paired BEGIN and END.

不过要注意 BEGIN TRANSACTION 命令,您不希望它们包含在替换中.

Look out for BEGIN TRANSACTION commands though, you don't want them included in the replace.

这篇关于如何在复杂的 SQL Server 查询中找到匹配的 BEGIN END 对?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆