If you are a database users then you may have observed while executing any query when it gives error and error message shows that on particular line number there is some issue. So we need to go to particular line number and correct the same. But what if your code is hundreds or thousands of lines, in that case scrolling down and finding that error line becomes quite difficult and time consuming.
SQL Server Management Studio provides an option to display line numbers in query editor window. In SSMS you can go to Tools –> and select Options…
It will pop up Options window as given below. Now navigate to Text Editor on left side options and select Transect-SQL –> General and in Display part choose Line numbers and click OK button. Now when when you will open a new query editor window, you will observe line numbers in it.
But if you don’t want to set line numbers in SSMS for every query editor window so there is one more option to directly go to particular line number by pressing Ctrl+G. When you will press it, you will get a pop up Go To Line to enter line number.
Here you can enter line number and press OK and your cursor will directly go to particular line number and you can correct the error.
SQL Server Management Studio (SSMS): Display Line Numbers
Losing your patience while writing long lines of code in SQL is understandable. SSMS includes a feature to show line numbers in your query editor to assist with this process. Instructions for SQL Server versions 2005, 2008, and 2012 are included.
By default line numbers are disabled in SQL server. However, through these steps they can be displayed with all versions of SQL Server.
Enabling line numbers option in SQL Server Management Studio (SSMS) is very useful in debugging. When errors are created, SSMS will show the line number to indicate the location of the issue. The following is an example:
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'FROM'.
Turning on line numbers makes it easy to jump to an line within the code by specifying the specific line number.
SQL Server 2008 and 2012
1.Open SSMS.
2.Under the Tools menu, select Options.
3.When Options window appears, expand the Text-Editor section.
4.When you see above window, span the Transact-SQL option and check the box Line Numbers under Display.
5.Now when you return to your query editor, the line numbers will be enabled.
SQL Server 2005
1. Under Tools Menu, select Options.
2. When the Option window appears, expand the Text-Editor option and select All Languages.
3. Select Line Numbers.
4. Return to your query editor, line numbers would be enabled.
2. When the Option window appears, expand the Text-Editor option and select All Languages.
3. Select Line Numbers.
4. Return to your query editor, line numbers would be enabled.
We will be glad to read your comments. Let us know if this really helped you to increase your productivity.
If you are a fan of displaying line numbers, you will probably want to review how to do this is in Visual Studio text editor and and Vi/Vim as well.