SSMS Tips and Tricks 1-3: Script multiple objects at once

If you want to script all the indexes on a table (or all the tables, all the stored procedures, etc, etc.), you can do that the long way by using the Generate Scripts right-click option for a database, but there’s a better way.
Let’s use the Purchasing.PurchaseOrderLines table from WideWorldImporters as an example. Here are the indexes on it:
The scripting options are well-known. You right-click the object, and can navigate to the scripting option:
But this is tedious when you want to script a whole set of them. Instead, start by clicking on the Indexes node itself:
When it’s selected, click F7 to open the Object Explorer Details pane:
Then click the top item, shift-click the bottom item (to select them all), and finally right-click to see that you can script all of them at once:
You could also use Control-click to select just the ones you want. This is also an easy way to drop more than one at the same time as well.
I hope that helps someone out there who wasn’t aware of this.
2025-05-11