This is a tip on how to show line numbers in your SQL Server Management Studio (SSMS) query window. This can be useful for when you receive an error with reference to a line in your code, although it’s not a necessity having it enabled as you’ll see below.
I’ve created a simple script to create a table and insert some rows into it. The date of birth on the 4th insert is not in the correct format, the year is expected as YYYY.
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.
Drill into Text Editor > Transact-SQL > General and tick Line numbers.
Now if we look at our query window, we’ll see numbers displayed.
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 run/save.
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 where 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.