Simple SQL Server Management Studio Trick: Multiple Line Text Editing
I've bumped into a few folks over the past year or so who simply don't know that you can easily edit (contiguous/similar) details across multiple lines in SQL Server 2012 —so I thought I'd share.
March 25, 2014
I'm hesitant to call this a trick—simply because there's nothing special to it (i.e., it's taking advantage of known/existing editing functionality from within SQL Server Management Studio, or SSMS)—and because I assume most people should know about it. On the other hand, I’ve bumped into a few folks over the past year or so who simply don’t know that you can easily edit (contiguous/similar) details across multiple lines in SQL Server 2012—so I thought I would share.
Holding down the ALT Key allows you to select/modify text on multiple lines
The trick itself is simultaneously simple—yet, powerful (one of those things that can save you a lot of time (over time) if you know it well)—and rests solely in the ability to be able to select and change text on multiple lines by holding down the ALT key when selecting text.
To put that into perspective, say I've created and typed the following query:
Then, assume that instead of pulling back job_ids, I want to join msdb.dbo.sysjobhistory against msdb.dbo.sysjobs—and pull out the name as well. To do so, I’ll just alias sysjobhistory as jh and JOIN it against sysjob (aliased as j):
Then, SQL will mostly run fine—other than the ambiguous column name of job_id—which shows up in both tables.
To get around the ambiguous column name (and, more importantly to have cleaner/better SQL), I should just alias/add "jh." in front of the columns already defined in my SELECT statement. Without the ability to ALT+edit multiple lines of code, that'd probably look like a) selecting “jh.” text; b) copying it into the clip board; and c) going from row to row (i.e., 4 times) and pasting "jh." in front of the existing column names.
With the ability to select/edit multiple lines, if I just hold down the ALT key and 'draw a line' or 'drag a line' down the 'front' of the columns already in place, I end up with a cursor/caret that spans all 4 lines. And, when I type in the literal text "jh."—then the text is added/inserted on all 4 lines at once. Here’s an animated GIF showing how that looks:
Again, this is nothing special or 'tricky'—it’s a built-in editing feature for SSMS 2012. My GUESS is that most developers know about it (as this kind of functionality has been in Visual Studio for quite a while now), but that many SysAdmins/DBAs might have 'missed the memo' on such functionality being added.
Either way, once you know about it and start to internalize and use it, it can be a nice productivity boost when pounding out lots of 'admin-y' kinds of queries and operations where there's a lot of text manipulation going on.
About the Author
You May Also Like