If there's one keyboard shortcut I use more than any other (with the exception of copy and paste) it would be the ALT + highlight multi-line edit/block selection shortcut.
Let's take a look at three ways the ALT + highlight shortcut lets you work faster in SQL Server Management Studio.
1. Add results of one query into the IN() statement
Sometimes when writing an ad hoc query you might want to take the results of one query and put them into an IN() statement of another query.
Sure, you can write a subquery to put into your IN() statement...but that's too much work for a one-time use disposable query.
What you can do instead is:
- Copy your values of interest
- Paste them into your IN() statement
- Hold down the ALT key while dragging the mouse down in front of all of your pasted values
- Type a comma (see video above for an easier demonstration).
This allows you to quickly turn pasted values into a list suitable for an IN() statement.
2. Paste values into a template of commands
Sometimes you might have to do something repetitive, like insert a bunch of values into a table. You could script out multiple value insertion with a UNION ALL and and INSERT INTO statement, but once again that's a lot of work for a one-time query.
Instead you can copy the values you want to insert by highlighting them while holding down the ALT key then positioning the cursor on the first location where you want to paste the values. Then once you paste, SSMS will automatically multiline paste the values.
Once again, watch the video above to see a demo - a picture (video!) is worth a thousand words.
3. Quickly modify multiple rows
Finally, you might have ran into a situation where you already have a set of queries written, but they all need to be slightly modified in order to work. For example, maybe the table name changed and now you need to append a prefix to each table name.
While holding down the ALT key, you can simply drag in front of the text you want to prepend to and then start typing.
Voila! You just edited multiple lines in one go.