Select Distinct Logo Clear Background

Business Analytics Blog

How to show line numbers in SQL Server Management Studio

Using Line Numbers in SQL

Using Line Numbers in SQL (SSMS)

Showing line numbers in SQL Server Management Studio is a simple tip that can really help users to quickly debug and find their away around  large SQL scripts

Why use line numbers in SQL Server?

The primary benefits from enabling line numbers in SQL Server Management Studio are

Finding Errors – SQL error messages can tell you which line of code an error is on, making finding it a lot quicker, particularly as scripts get larger

Navigation – You can use the Go to function to go straight to a specific row, useful on long scripts, saving the need for scrolling through code

How to enable line numbers in SQL Server Management Studio (SSMS)?

To show line numbers in SQL Server Management Studio (SSMS)

Click on Tools at the top of the SSMS screen

SSMS Menu screen showing tools

Then Select Options

and within the options settings, navigate to Text Editor, then Transact SQL and General

Within the general settings is a box for Line Numbers, ensure it is ticked and click OK

SSMS Options Menu screen

You should now see line numbers in the left hand margin in the SQL editor window, the line numbers are shown in green as below

SQL editor screen showing line numbers

You can now see exactly with line of code relates to any error messages

Using the Go To Line option in SSMS

If you need to quickly navigate to a specific line of code, you can use the Go To line function

Make sure you have the SQL editor window selected or you may not see the option

On the title menu, select Edit, then select Go To and at the top of the list is the Go To Line option

(or you can use the CTRL + G shortcut)

SQL Go To Line dialogue box

This takes you straight to the line number you select, saving you time scrolling

Showing Line Numbers in SQL is very easy, just set the option once and it will keep the settings, continuing to help you find your way quickly around SQL code

But if you move to a new instance of SSMS, such as using it on a new virtual machine, it is probably one of the first thigns you want to do. So we created this post to help remind you how

You may be interested in this post
Top SQL Tips for 2023

Subscribe to our channel to see more Timesavers

Select Distinct YouTube Channel

Our Business Analytics Timesavers are selected from our day to day analytics consultancy work.  They are the everyday things we see that really help analysts, SQL developers, BI Developers and many more people.

Our blog has something for everyone, from tips for improving your SQL skills to posts about BI tools and techniques. We hope that you find these helpful!

Business Analytics Blog

By Simon Harrison

Simon Harrison Founder of Select Distinct Limited and a business intelligence expert