How to Show Line Numbers in SQL Server Management Studio
The Line Number setting in SQL Server Management Studio (SSMS) adds a numbered gutter beside each line in Query Editor. It is an editor-display preference only: it does not change the SQL Server instance, affect query execution, or alter result data. Use it to navigate long scripts, discuss a query with teammates, and locate reported error lines faster.
Use this quick reference when you need the right kind of numbering.
| What You Need | Setting or Action |
|---|---|
| Show line numbers beside SQL code in SSMS | Tools > Options > Text Editor > Transact-SQL > Settings, then select Line Number |
| Move the cursor to a specific code line | Press Ctrl+G or choose Edit > Go To |
| Number rows returned by a query | Use ROW_NUMBER() OVER (...) in the query |
| Show line numbers in VS Code-based tools | Set editor.lineNumbers to on in editor settings |
What SSMS Line Numbers Mean
SSMS line numbers identify physical lines in the text editor. They include blank lines, comment lines, and lines that do not contain a complete SQL statement.
For example, a comment on one line, a blank line below it, and a SELECT statement on the next line each receive their own number. A long statement that visually wraps in the editor remains one physical line unless you inserted a line break.
This is useful when:
- SQL Server reports an error location.
- You need to tell someone where to edit a stored procedure or deployment script.
- You are reviewing a large query with comments and multiple batches.
- You want to jump directly to a location instead of scrolling.
How to Show Line Numbers in SSMS
Enable the Line Number checkbox in the Transact-SQL editor settings to display numbers beside SQL text in Query Editor.
Step 1: Open the SSMS Options Dialog
- Open SQL Server Management Studio.
- From the main menu, select Tools > Options.
- Expand the Text Editor section in the left pane.
This setting is stored by SSMS as part of its editor preferences. The setting is available from the Options dialog before you open a query window.
Step 2: Enable the Transact-SQL Editor Setting
- Under Text Editor, select Transact-SQL.
- Select the Settings page under Transact-SQL.
- Select the
Line Numbercheckbox. - Select OK to save the preference.
Some SSMS versions place the same control under Text Editor > Transact-SQL > General rather than a page labeled Settings. If you do not see Settings, open the Transact-SQL General page and enable the line-numbering checkbox there.
Choose the Transact-SQL-specific option rather than relying on an all-languages setting when your goal is to configure SQL query windows.
Step 3: Return to Query Editor and Confirm the Display
- Return to an existing query window or open a new one with New Query.
- Look at the left margin of Query Editor.
- Confirm that a vertical list of numbers appears beside the SQL text.
The numbers are shown in a separate gutter, so they do not become part of your script when you copy, save, or run it. To turn the display off later, return to the same editor preference and clear the checkbox.
Navigate Long SQL Scripts With Go To
Once the gutter is visible, you can quickly move to a location by pressing Ctrl+G. SSMS opens the Go To dialog, where you enter the destination line and confirm the move.
This is especially useful when an error message, code review comment, or teammate references a line in a script. The Go To dialog also shows the highest available line in the active editor, which gives you a quick way to determine the script’s total physical line count.
Keep these details in mind:
- Wrapped display text does not create additional line numbers.
- The line count applies to the current query document, not every open tab in SSMS.
For shared scripts, leave comments and blank lines in place while investigating a reported location. Removing or adding lines before the reported area shifts the visible positions for everyone reading the file.
Understand Errors, Batches, and Query Results
Editor line numbers, SQL Server error lines, and result row numbers refer to three different things.
The number in the SSMS gutter is a location in the query text. A SQL Server error line identifies where SQL Server encountered a problem while processing a submitted statement, batch, or stored procedure. A result row number is data produced by a query.
Error Messages and Visible Script Lines
Enabling the editor gutter does not change what SQL Server reports in the Messages tab. The gutter gives you a visual reference for finding a reported location.
When locating code mentioned in an error message, consider these script structures:
- Multiple batches separated by
GO - Dynamic SQL executed with
EXECorsp_executesql - A stored procedure, trigger, or function called from another script
- Generated SQL whose text differs from the file you are viewing
GO is a client-side batch separator recognized by tools such as SSMS; it is not a Transact-SQL statement sent to the server. Use the batch or module named by the error message to narrow the search.
Numbering Rows in Query Results
If you want sequential numbers in the Results grid, use the ROW_NUMBER() window function. This is unrelated to the editor gutter.
SELECT
ROW_NUMBER() OVER (ORDER BY CustomerID) AS ResultRow,
CustomerID,
CustomerName
FROM dbo.Customers
ORDER BY CustomerID;
Replace CustomerID, CustomerName, and dbo.Customers with columns and a table from your database. The ORDER BY inside ROW_NUMBER() defines the sequence used for the row numbers, so choose a column or combination of columns that produces the order you actually need.
Do not rely on the order in which SQL Server happens to return rows without an ORDER BY. A result set has no guaranteed presentation order unless the query specifies one.
Show Line Numbers in Other SQL Editors
SSMS is not the only place you may write Transact-SQL. The setting belongs to the editor you are using, not to SQL Server itself.
Visual Studio and SQL Server Data Tools
In Visual Studio with SQL Server Data Tools or database projects, open Tools > Options > Text Editor > Transact-SQL > General. Enable the line-numbering option for the Transact-SQL editor, then return to the .sql file.
The exact labels can differ slightly between Visual Studio releases, but the setting is normally under the Transact-SQL editor preferences rather than database project properties.
VS Code and VS Code-Based SQL Tools
In Visual Studio Code, open Settings and search for editor.lineNumbers. Set the editor line-number option to on.
This setting also applies to SQL files when you use a SQL extension. If you are still using Azure Data Studio, search its settings for the same editor option because it uses the VS Code-style editor configuration.
Online SQL Editors
A browser-based SQL editor can show code line numbers only if that particular website provides an editor-gutter option. SQL Server cannot force a web page to display them.
Look in the online editor’s display, appearance, editor, or preferences settings. If the site does not offer a line-number gutter, use a local editor such as SSMS or VS Code when you need dependable line references for debugging or collaboration.
Confirm and Troubleshoot the SSMS Display
After changing the preference, verify that it works in an actual SQL query window rather than in Object Explorer, the Results grid, or a plain-text dialog.
Use this checklist:
- Open a Query Editor tab.
- Confirm that numbers appear in the narrow left margin beside the code.
- Press
Ctrl+Gand verify that SSMS opens the Go To dialog. - Run a simple query and confirm that the numbered gutter remains visible in Query Editor.
If the numbers do not appear, try these fixes in order:
- Check that you changed the Transact-SQL editor settings, not a different language’s editor settings.
- Look for the option under General if the Transact-SQL node does not contain a page called Settings.
- Close the query tab and open a new query window.
- Restart SSMS if the editor did not refresh after saving the option.
- Verify that you are looking at Query Editor. Line numbers do not appear beside rows in the Results or Messages panes.
If you need sequential numbers for returned records instead, use ROW_NUMBER() in the query output. Next, enable the gutter in your Query Editor and use Ctrl+G whenever an error message or review comment points you to a specific location.
Frequently Asked Questions
How Do I Find the Total Number of Lines in an SSMS Script?
Press Ctrl+G in the active Query Editor window. The Go To dialog shows the maximum available line for that document, including blank lines and comments.
This count applies to the current editor tab. It does not count lines in stored procedures, scripts, or files that are not open in that tab.
Does Showing Line Numbers Affect SQL Server Performance?
No. Showing line numbers is a client-side SSMS display preference, so it does not change query plans, server CPU usage, database storage, or the data returned by a query.
It is safe to leave enabled for normal development, debugging, and database administration work.
Can SQL Server Return the Line That Raised an Error?
Yes. Inside a CATCH block, ERROR_LINE() returns the line number where the error occurred in the executed Transact-SQL batch or module.
BEGIN TRY
SELECT 1 / 0;
END TRY
BEGIN CATCH
SELECT
ERROR_LINE() AS ErrorLine,
ERROR_MESSAGE() AS ErrorMessage;
END CATCH;
Use ERROR_LINE() with ERROR_MESSAGE(), ERROR_NUMBER(), and ERROR_PROCEDURE() when writing error-handling code that needs useful diagnostic output.
Can I Number Only SQL Statements Instead of Every Text Line?
No. SSMS numbers physical text lines, so comments and blank lines receive numbers too. This is intentional because the editor needs to identify an exact position in the script.
