How to Show Line Numbers in SSMS

🛠️Part of the SSMS Complete Guide, installing, configuring and fixing SQL Server Management Studio.

⚡Tools → Options, search for “line numbers”, and tick Line numbers. Current SSMS has them on already. If they still do not show in query windows, the Transact-SQL language page has its own copy of the setting.

Line numbers sit down the left margin of every query window in SSMS 21 and later, with nothing to switch on (Install and Update SSMS if you are on an older version). If yours are missing, or you want them gone, tick or untick Line numbers under Tools → Options. They matter most when an error message names a line, which most syntax errors do.


Turn Line Numbers On or Off

  1. In SSMS, open Tools → Options.
  2. Type line numbers into the search box at the top, or open Languages → Defaults → General in the tree.
  3. Tick or untick Line numbers. The settings page saves as you go, so just close it.
SSMS 22 Tools Options, All Settings, Languages, Defaults, General, with Line numbers ticked

Defaults is the global setting for every language. If line numbers still do not appear in query windows, open Languages → Transact-SQL → General: each language has its own copy of the setting (Display line numbers, the Visual Studio page SSMS inherits this from).

SSMS 21 and earlier use the older Options dialog: Text Editor → Transact-SQL → General (or All Languages → General for every language), then OK. SSMS 20 and earlier had line numbers off by default.


Using Line Numbers With Errors

Most syntax errors name the line where the parser gave up. This five-line query has a stray bracket on line 4:

SELECT name
FROM sys.databases
WHERE database_id > 4
  AND name = 'master')
ORDER BY name;
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near ')'.

Line 4 is where the bracket is, so you go straight there instead of counting. The number counts from the start of the batch, not the file: in a script split by GO, the same error after one earlier batch still reports Line 4 even though it sits further down the editor. Error 102 explains why the quoted token is where the parser stopped rather than where the mistake is.

SSMS 22 query window with line numbers down the left margin

Navigating to a Specific Line

  • Double-click an error in the Messages pane to jump to the line it names.
  • Press Ctrl + G to go to a line number directly.
  • When someone on a call says “look at line 42”, everyone lands on the same line.

Final Notes

Line numbers change nothing about how SQL runs. On current SSMS they are on by default, and the only time you need the setting is when an install or an imported settings file has turned them off.

Where To Go Next

Dark mode is the other editor quality-of-life switch worth flipping: here is where it lives. This page covers one part of working with SSMS. The full reference ties the install, configuration and troubleshooting pieces together.

More in this series: Install and Update SQL Server Management Studio (SSMS) · DBA Scripts: Install and Update SSMS via PowerShell · DBA Scripts: Uninstall SSMS via PowerShell

Comments

Leave a Reply

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