Menu & Search
SSMS Show Line Numbers

SSMS Show Line Numbers

This is a tip on how to show line numbers in the SQL Server Management Studio (SSMS) query window.

Showing line numbers in SSMS is something that you may prefer to have enabled as default. As well as general preference, enabling this 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, 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).

Share

1 Comment

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