Learn more about SQL Server tools

   
   















































Display Line Numbers in a SQL Server Management Studio Query Window

MSSQLTips author Ashish Kumar Mehta By:   |   Read Comments (21)   |   Related Tips: More > SQL Server Management Studio
Problem

Often we see an error message from SQL Server which references a particular line number within our T-SQL code. It is a little frustrating to find the line number where the syntax error has occurred. In this tip we will take a look at how to quickly enable line the numbers feature in SQL Server Management Studio.

Solution

Let us see how to enable or disable the display of line numbers in SQL Server Management Studio's Query Window.

1. Open SQL Server Management Studio. Click Tools -> Options from the drop down menu as shown in the below to open up Options dialog box.

Tools and Options menu in SQL Server Management Studio

2. In the Options dialog box on the left side panel expand the Text Editor option and expand Transact-SQL. Next select General as shown in the snippet below.

Options Dialog Box in SSMS

3. In the General page's right side panel you need to select the check box "Line numbers" under the Display section as shown in the above snippet and click OK to save the changes.

4. Going forward whenever you open a new query window in SQL Server Management Studio you will see line numbers displayed. In the below snippet you will see that line numbers are displayed in the sample T-SQL code. This feature is very helpful when you need to debug an error in your T-SQL code, especially in scenarios when SQL Server mentions that error is found on a particular line number.

SSMS Query Window Showing Line Numbers

5. If this feature in not turned and you need to go to a particular line number press CTRL + G to open Go To Line dialog box; enter line number and click OK as shown below.

Specify Value of the line number in SQL Server Management Studio

6. To turn off the line number feature in SQL Server Management Studio you need to navigate to Tools | Options | Text Editor | General | Display and uncheck the Line Number check box and click the OK button to save the changes so that next time you open a new query window in SSMS line numbers will not be displayed.

Next Steps


Last Update: 7/23/2012


About the author
MSSQLTips author Ashish Kumar Mehta
Ashish Kumar Mehta has been contributing to the MSSQLTips.com community since 2009 with over 60 tips.

View all my tips
Related Resources


print tip Print  
Become a paid author





join MSSQLTips for free SQL Server tips     



Learn more about SQL Server tools
Post a comment or let the author know this tip helped you.

       All comments are reviewed, so stay on subject or we may delete your comment.

*Name   *Email Notify for updates



       Note: your email address is not published. Required fields are marked with an asterisk (*)


Get free SQL tips:

*Enter Code refresh code     



Wednesday, August 20, 2014 - 9:38:57 AM - Murray Read The Tip

This is great!  Thanks so much.  Also huge thanks to Fatherjack for his tip as well!

 


Monday, May 19, 2014 - 6:55:48 AM - babu Read The Tip

I Love MSSQLTips as they bringing something new every day for every learner.


Monday, May 19, 2014 - 6:53:37 AM - Ravi Read The Tip

Thank you


Monday, May 19, 2014 - 6:52:46 AM - babu Read The Tip

 

Thanks, chaps, that's a very useful one.


Thursday, April 24, 2014 - 3:20:33 AM - Babłke Read The Tip

Thank you


Friday, October 25, 2013 - 12:15:37 PM - Shelly Read The Tip

Well, I'm a "seasoned beginner" and I did not know how to turn on the line count, nor about the double-click error jump.  I like having some basic tips and they are not only for beginners.  If I do not consistently use a tool, I will forget about it.  Then when I need it, I can't remember how to get to it.  Thanks for sharing and keep the basic reminders coming. 


Saturday, October 12, 2013 - 1:54:26 AM - Arnor Baldvinsson Read The Tip

Thanks for this tip!  I'm not new to SSMS, but I haven't written much SQL code in it - done that in external tools.  A quick google searched showed this article.  Simple when you know how to;)

Best regards,


Monday, May 20, 2013 - 8:41:00 AM - Josetta Read The Tip

Thanks for the tip. I'm not an absolute beginner, but I'd have spent way too much time looking for this myself. Also, handy to know that double-clicking the error takes me right to the error. But I DO know how to turn my computer on, so no need for a tip on that. :)

Thanks again!!


Tuesday, August 07, 2012 - 12:48:48 PM - Gene Wirchenko Read The Tip
Zen: Yes, it was a tip, and it was useful to me. If you did not need it, fine, but that does not mean that no one else did.

Tuesday, August 07, 2012 - 9:10:00 AM - Dom Read The Tip

If you have more than one script in a query window, which I do often enough, then it is frustrating to find the the error message gives you a line number *within the specific script*.  That is, if the error message complains about line 17, it is not really line 17, it is the 17th line withing the scipt.  In that case, double-clicking the error message is really the only way to find the offending line.


Tuesday, July 24, 2012 - 8:38:29 AM - Jeremy Kadlec Read The Tip

Zen,

Please send me a direct email (jeremyk@edgewoodsolutions.com).  I would like to hear your feedback.

Thank you,
Jeremy Kadlec


Tuesday, July 24, 2012 - 6:12:15 AM - Miki Breakwell Read The Tip

Thanks, chaps, that's a very useful one.

 


Monday, July 23, 2012 - 9:10:10 PM - Bill Fennell Read The Tip

Yeah, you never know who's reading a tip, so it's good to include newbies where possible.  Don't forget... we were also newbies at one point.

Another cool thing in SSMS around line numbers is if you double-click an error message in the results pane, it usually takes you to the line that has the error!

=B-)


Monday, July 23, 2012 - 11:08:31 AM - Daniel Read The Tip

Wow! Thanks MSSQLTips for this quick tip.

I had seen Line Numbers display in SSMS while attending few webcasts and always wondered how to get this feature enabled as this is so useful in day-to-day work.

Thanks for pointing out how to enable this.

I Love MSSQLTips as they bringing something new every day for every learner.


Monday, July 23, 2012 - 11:00:13 AM - TimothyAWiseman Read The Tip

@Zen There is room for tips that are targetted at the absolute beginners as well.  We were all beginners once and I see nothing wrong with trying to help them at. 


Monday, July 23, 2012 - 10:42:49 AM - niyidele@gmail.com Read The Tip

Wow....this really helps! I am new to SQL Server. You a life saver!!!!


Monday, July 23, 2012 - 9:10:37 AM - Greg Robidoux Read The Tip

@Zen - thanks for your feedback.  The thing to keep in mind is that the site has various levels of people using SQL Server.  Some things that may be very obvious to some are not so obvious to others such as this tip. 

Thanks again for your feedback and we'll try to balance the tip topics the best we can.


Monday, July 23, 2012 - 9:04:45 AM - ZEN Read The Tip

 

How to display line # in SSMS?   huh... Are you kidding me? I am not saying to the writer.  I am saying to Jeremy.  Could next MSSQL TIPS be how to turn on your computer???

 

We love this website because of it's contents and this is really not TIPS at all. 


Monday, July 23, 2012 - 8:56:27 AM - Greg Robidoux Read The Tip

@fatherjack - thanks for pointint that out.  We actually have a tip on doing just that: http://www.mssqltips.com/sqlservertip/1101/finding-sql-server-code-errors-using-query-analyzer/


Monday, July 23, 2012 - 8:38:35 AM - Sanjeev Viswanath Read The Tip

Dear All,

I have enabled the deadlock trace flag 1222 on my server . But I am not able to interpret the error logs after  deadlock occurs on it .

Can anyone help me on this.

Below is the sample error log after deadlock occured. Any help is appreciated.

#################

<deadlock>

  <victim-list>

    <victimProcess id="process1ac25288" />

  </victim-list>

  <process-list>

    <process id="process1ac25288" taskpriority="0" logused="52264" waitresource="OBJECT: 7:1618156860:41 " waittime="19938" ownerId="889665194" transactionname="user_transaction" lasttranstarted="2012-07-13T03:30:00.233" XDES="0x23602ec3b0" lockMode="IX" schedulerid="42" kpid="14536" status="suspended" spid="57" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2012-07-13T03:30:00.233" lastbatchcompleted="2012-07-13T03:30:00.233" clientapp="crmnext" hostname="HBSFATDB" hostpid="18360" loginname="HBSFATDB\casper" isolationlevel="read committed (2)" xactid="889665194" currentdb="7" lockTimeout="4294967295" clientoption1="671219744" clientoption2="128056">

      <executionStack>

        <frame procname="" line="30" stmtstart="1954" sqlhandle="0x030007002d78ce07332a880088a000000000000000000000" />

        <frame procname="" line="14" stmtstart="1628" stmtend="3242" sqlhandle="0x03000700e40d6902d593960088a000000100000000000000" />

      </executionStack>

      <inputbuf>

Proc [Database Id = 7 Object Id = 40439268]   </inputbuf>

    </process>

    <process id="process1c688748" taskpriority="0" logused="335974140" waitresource="KEY: 7:72057597604724736 (855f87e921e1)" waittime="2172" ownerId="889663938" transactionname="user_transaction" lasttranstarted="2012-07-13T03:29:58.467" XDES="0x3e91cf7950" lockMode="U" schedulerid="112" kpid="21260" status="suspended" spid="59" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2012-07-13T03:29:58.467" lastbatchcompleted="2012-07-13T03:29:58.467" clientapp="crmnext" hostname="HBCRMPRDAP1" hostpid="22212" loginname="HBSFATDB\casper" isolationlevel="read committed (2)" xactid="889663938" currentdb="7" lockTimeout="4294967295" clientoption1="671219744" clientoption2="128056">

      <executionStack>

        <frame procname="" line="14" stmtstart="760" stmtend="1100" sqlhandle="0x030007007d8ec66afb2b880088a000000000000000000000" />

        <frame procname="" line="1" stmtstart="74" sqlhandle="0x02000000eac2ff2d89337e6bd2413fabc1a8bf7e1057da80" />

        <frame procname="" line="1" sqlhandle="0x000000000000000000000000000000000000000000000000" />

      </executionStack>

      <inputbuf>

(@maxtotalattempts int,@statusid int)DELETE FROM ClusteredOperationControl   WHERE TotalAttempts &gt; @maxtotalattempts OR StatusID in( @statusid,5)   </inputbuf>

    </process>

  </process-list>

  <resource-list>

    <objectlock lockPartition="41" objid="1618156860" subresource="FULL" dbid="7" objectname="" id="lock410e287900" mode="X" associatedObjectId="1618156860">

      <owner-list>

        <owner id="process1c688748" mode="X" />

      </owner-list>

      <waiter-list>

        <waiter id="process1ac25288" mode="IX" requestType="wait" />

      </waiter-list>

    </objectlock>

    <keylock hobtid="72057597604724736" dbid="7" objectname="" indexname="" id="lock4b239d5200" mode="X" associatedObjectId="72057597604724736">

      <owner-list>

        <owner id="process1ac25288" mode="X" />

      </owner-list>

      <waiter-list>

        <waiter id="process1c688748" mode="U" requestType="wait" />

      </waiter-list>

    </keylock>

  </resource-list>

</deadlock>

###########3

Regards

Sanjeev Viswanath


Monday, July 23, 2012 - 7:52:37 AM - fatherjack Read The Tip

Did you know that you can double click the error message and SSMS jumps you to the start of the offending piece of TSQL too?




 
Sponsor Information