Display Line Numbers in a SQL Server Management Studio Query Window

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 SSMS to show line numbers 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.

Turn On SSMS Show Line Numbers

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

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.

SSMS show line numbers option

In the General page’s right side panel you need to select the check box “Line numbers” as shown in the above snippet and click OK to save the changes. Note: in new versions of SSMS the screen looks a little different from above.

Show line numbers in SSMS query

When you open a new query window in SQL Server Management Studio you will see line numbers displayed. Below you can 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 when SQL Server mentions that error is found on a particular line number.

SSMS Query Window Showing Line Numbers

SSMS Go To Line

In SSMS, you can use CTRL + G to open the Go To Line dialog box, enter line number and click OK as shown below to go to that specific line of code.

Specify Value of the line number in SQL Server Management Studio

Turn Off SSMS Show Line Numbers

To turn off the line number feature in SQL Server Management Studio navigate to Tools > Options > Text Editor > Transact-SQL > General and uncheck the Line Numbers check box and click the OK button to save the changes. When you open a new query window in SSMS the line numbers will not be displayed.

Next Steps

5 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *