如何从错误消息中获取实际的存储过程行号? [英] How can I get the actual stored procedure line number from an error message?

查看:36
本文介绍了如何从错误消息中获取实际的存储过程行号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 SQL Server 并且出现错误时,错误消息给出的行号与存储过程中的行号没有关联.我认为差异是由于空格和注释造成的,但真的是这样吗?

When I use SQL Server and there's an error, the error message gives a line number that has no correlation to the line numbers in the stored procedure. I assume that the difference is due to white space and comments, but is it really?

如何将这两组行号相互关联?如果有人能给我至少一个正确方向的指示,我将不胜感激.

How can I relate these two sets of line numbers to each other? If anyone could give me at least a pointer in the right direction, I'd really appreciate it.

我使用的是 SQL Server 2005.

I'm using SQL server 2005.

推荐答案

IIRC,它从创建该 proc 的批处理的开始开始计算行数.这意味着要么是脚本的开始,要么是 create/alter proc 语句之前的最后一个GO"语句.

IIRC, it starts counting lines from the start of the batch that created that proc. That means either the start of the script, or else the last "GO" statement before the create/alter proc statement.

一种更简单的查看方法是提取 SQL Server 在创建对象时使用的实际文本.将输出切换到文本模式(CTRL-T 使用默认键映射)并运行

An easier way to see that is to pull the actual text that SQL Server used when creating the object. Switch your output to text mode (CTRL-T with the default key mappings) and run

sp_helptext proc_name

将结果复制粘贴到脚本窗口中以获得语法高亮等,并使用goto line函数(我认为是CTRL-G)转到报告的错误行.

Copy paste the results into a script window to get syntax highlighting etc, and use the goto line function (CTRL-G I think) to go to the error line reported.

这篇关于如何从错误消息中获取实际的存储过程行号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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