SQL Server Go To Line

Show Line Numbers in SQL Server Management Studio (SSMS)

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

This is useful when you receive an error message with reference to a line in your code, although it’s not a necessity to have it enabled as you’ll see in the demo below. Also, some folks might prefer to have this enabled as a standard when writing code.

In this first part of this info post, I’m creating a test table and throwing an intentional error message (dateofbirth column on the 4th insert is not in the correct format) –

Conversion failed when converting data and/or time from character string

If we count down the lines of code we’ll get to a problem on the 4th insert, line number 8.

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.

Show Line Numbers SQL Server Management Studio

Now if we look at our query window, we’ll see numbers displayed.

SSMS Line Number

If we double-click the error line, as shown above, it’ll jump to the referenced row whether you have lines shown or not. You can also use the Go To Line feature by hitting CTL+G.

In this next image, I’ve entered a breaking line in one of the default database system stored procedures to which SQL results in an error when I try to run/save.

go to line number

The fail-line referenced is not always entirely accurate, as you can see above. I’d say most of the time the problem area is easy to spot, however, will be times when it’s not for sure.

Enabling line numbers will visually make it easier to see problem lines of code and it can also be handy for presenting. Other than that, it’s a general preference really.

Comments

Leave a Reply

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