Select and Edit Vertical Blocks in SQL Server Management Studio ( SSMS) - SQL Server / TSQL Tutorial Part 9


We often come to situation where we need to make same changes to multiple line of code. This is great feature to make quick change to tsql script.

Take a look into below script,I would like to change Testdb1 to testdb2 for first three queries. We might think that we can use Find and Replace, that can be used but we have to replace one item at a time as our each query is using Testdb1. By using SSMS Edit Vertical Blocks feature we can replace Testdb1 with testdb2 for three queries quickly.

Use master
Select * From testdb1.dbo.test1 union all
Select * From testdb1.dbo.test2 union all
Select * From testdb1.dbo.test3 union all
Select * From testdb1.dbo.test4 union all
Select * From testdb1.dbo.test5 union all
Select * From testdb1.dbo.test


 It is simple to use , How down the Alt key and then select area you would like to select.

How to Select and Edit Vertical Blocks in SSMS - SQL Server Tutorial

Once the area is selected, Type the new word you would like to use, in our case we want to replace with TestDB2.
How to Select and Replace vertically in SSMS - SQL Server Tutorial

I noticed one thing, If there will be space( line) between the queries, It will type the new word there as well. that is annoying so make sure your queries don't have space between them.

Trying to add word to blank lines as part of replace in SSMS vertical Select and Replace Feature

No comments:

Post a Comment