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.
Navigate to Text Editor > Transact-SQL > General and tick Line Numbers.
Click OK, and you’ll see now see line numbers in the SSMS query window.
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.
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).
Leave a Reply