Little Trick to Save Time in SSMS

Written by

Actually, if we need to change , include , remove or select a pattern in our SQL code or SQL scripts, most of us follow some of the methods like

  • Manually going to each lines and does changes(not helpful for huge numbers)
  • Copy/Paste our Codes and do Excel works(for small numbers-it is not helpful; for huge numbers-it takes most of our time; Also we need to know Excel skills)

But 1 trick is there in SSMS itself and it works fine for both small and high number of lines. Also we don’t need Excel Skills for this and it also saves our time.

What it is?

Please follow the below 6 images for easy understandings (Explanation added in images itself!)

Dummy SQL Script – (Use the below A to Z Script To try!)

A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z

Images with Explanation

By two ways, we can try this.

  • One is Alt + Mouse Click and Drags
  • Another method is Keyboard Shortcut Alt + Shift + (Up,Down,Left,Right Arrows)

NOTE –

At any position (Front, Middle or End), we can apply/use this trick. we can select, include, remove and modify dragged content/code using this trick in SSMS (SQL Server Management Studio).

It is not useful, if scripts are NOT STRAIGHTLY ALIGNED like below pic.

NOT STRAIGHTLY ALIGNED

Real Life Scenario

Practical Advantage of this trick aka., one of the use case scenario is,
We can Drop Multiple Tables in a Single Query in SQL Server.

Here, say for example we need to delete some 20 dummy tables. we already have all those table’s name lists. Before we can add drop table syntax. But every line We need to add comma ‘,’ . Here, we can use this trick(at Front) in SSMS itself and save lot of our time.

Conclusion

Since this is related to SSMS Feature, it works fine in both Azure SQL DB and On-Premises. Unit Tested in both environments.

Thanks for reading and Follow Blog!

Article Categories:
SQL Server

Leave a Reply

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

Shares