How to add Line Numbers in SQL Server Management Studio ( SSMS) - SQL Server / TSQL Tutorial Part 11

Scenario:

As sql server developer we write a lot of scripts and every time error occur, it say error happened on line number x.

if you are using 3 lines code like me, you might be Ok to see which is third line :) but if your have 100,s of lines of code, it is good idea if you can see the line numbers next to code.  Question is, How to enable line Numbers and if I will copy this script, will line numbers will be copied as well?

Solution:

Open SQL Server Management Studio(SSMS). Go to Tools and then Options as shown below.
How to add line numbers in SSMS - SQL Server Tutorial

Now go to Text Editor, Then Transact-SQL and hit General. On Option windows check the Line Number Box under Display as shown below.

How to Add Line Numbers to SQL Script in SSMS - SQL Server Tutorial


Now you should see the Line Numbers next to your script, and If you will copy the script , it will not copy the line numbers with it. Line Numbers are there only for display.

Add line numbers to sql script in SSMS - SQL Server / T SQL Tutorial