Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server stored procedure line number issue

I am using SQL Server 2008 Enterprise. I met with issue which says line 9 of stored procedure foo is meeting with dead lock issue. My question is how to find exactly the 9th line of the stored procedure?

My confusion is because of coding format issue, how to locate 9th line correctly.

thanks in advance, George

like image 960
George2 Avatar asked Jun 01 '10 03:06

George2


2 Answers

A tip I learnt from another answer ...

If you do

sp_helptext procedure_name

SQL will output its 'remembered' version of the create procedure statement, and that is what it gets it line numbers from apparently. If you have SSMS in 'grid output' mode then it will also output the line numbers (as the row numbers of the result set).

NB: in my case it was working from the CREATE PROCEDURE statement plus a bunch of comments above it, so line 1 was about 6 lines above the CREATE PROCEDURE call.

like image 193
codeulike Avatar answered Nov 12 '22 23:11

codeulike


It's the 9th line from the CREATE PROCEDURE statement. A SQL statement is often multiline so "line 9" will refer to the first line of the statement (eg INSERT or UPDATE)

However, if you have comments above the CREATE PROCEDURE or blank lines before it then you can't rely on this... so run ALTER PROC with ALTER PROC as first line in the batch.

like image 35
gbn Avatar answered Nov 13 '22 01:11

gbn