SSMS Show Line Numbers

This post contains a guide on how to show line numbers in the SSMS query window. Useful if you want to see line numbers while you code.

As well as general preference, enabling line numbers in SQL Server Management Studio is particularly useful when debugging an error message in a SQL script.

The demo below includes the following:
# Show Line Numbers in SSMS
# Debugging Example

Show Line Numbers in SSMS

To enable line numbers in Management Studio, click Tools at the top menu bar and select Options.

SSMS Tools Options

Navigate to Text Editor > Transact-SQL > General and tick Line Numbers.

SSMS Show Line Numbers

Click OK, and you’ll see now see line numbers in the SSMS query window.

SSMS Line Numbers

Debugging Example

When you are debugging a SQL script within SSMS, showing line numbers might help you when encountering an error like this one below.

I’ve opened a random Stored Procedure, amended and attempted to run it, knowing it will fail.

SQL Error Line

The line our code has failed on is included in the output error message:
Msg 102, Level 15, State 1, Procedure sp_addlogin, Line 33 [Batch Start Line 7]
Incorrect syntax near ‘gif’.
Msg 156, Level 15, State 1, Procedure sp_addlogin, Line 35 [Batch Start Line 7]
Incorrect syntax near the keyword ‘else’.

Line numbers shown in these error messages aren’t always accurate, but it should give you a pointer to the section of broken code.

You can Double-Click the error message to bring you to the referenced line number, or use the Go To Line feature (CTRL + G).


Comments

2 responses to “SSMS Show Line Numbers”

  1. […] The demo below includes the following:# Show Line Numbers in SSMS# Debugging Example […]

  2. […] SSMS Maximum Characters Displayed, September 12, 2022– SSMS Show Line Numbers, September 3, 2022– How to Connect to SQL Server with Windows Authentication using a Different […]

Leave a Reply

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