Shortcut: Using line numbers and Go To in SQL Server Management Studio (SSMS)

If you ever have long scripts in SQL Server Management Studio and need to refer to a particular line, it can be helpful to have line numbers shown. This is even more useful if you ever need to write a set of instructions for someone on how to modify a query, or if you are trying to describe how a query works.

Instead of having a query like this:

In Tools, then Options, then Text Editor, then Transact-SQL, on the General tab, there is an option for Line Numbers:

Once that’s enabled, the query windows look like this:

The line numbers go in a separate margin. Note that all lines are numbered, unrelated to whether or not they contain an individual SQL statement.

If you have a long script and you need to quickly, reposition the cursor, note that you can also go directly to a line number. On the Edit menu, you can see that Ctrl-G is the shortcut for Go To.

Hitting Ctrl-G pops up a dialog and asks me for a line number:

Then takes me straight there. Note that in the dialog, the maximum line number is shown.

One thought on “Shortcut: Using line numbers and Go To in SQL Server Management Studio (SSMS)”

  1. I *always* turn line-numbers on. One big side-effect of this is that it’s MUCH easier to select a line or block of text, by just positioning the cursor over the line number and click-dragging. Selection of blocks of SQL for copy/pasting is much faster and far more convenient using this “line select”. You can do it without the numbers, but the target area is so small, it’s generally too difficult to bother with.

Leave a Reply

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