Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script out multiple database objects at once in SSMS

The Script as option (available in right click menu on any object in Object Explorer) in SSMS is really handy to script out objects for alter, create and select and several other operations. enter image description here

I use it often. But I see it does not let me script out multiple objects (say multiple tables) at once. Holding down the Ctrl or Shift key does not let me select multiple objects. Recently I needed to compare schema for 3-4 tables across different QA environments, so I had to script out the tables one table at a time and repeat it in all QA environments.

Is there way from SSMS to script out multiple objects at once? Selecting one object at a time and scripting it out is irritating.

like image 439
HappyTown Avatar asked Jan 27 '17 16:01

HappyTown


1 Answers

This can be done exactly as requested by:

1) Menu: View -> Object Explorer Detail (F7)

2) Click on "Tables" folder in the Explorer tree and the tables will show in the Object Explorer Detail.

3) Select in the Object Explorer Detail tables you need and then as usually "Script table as..." --> CREATE TO --> New Query Window (or whatever you prefer).

enter image description here

Unfortunately, this works for CREATE TO and DROP and such, but not for SELECT, INSERT TO, etc.

like image 173
Oak_3260548 Avatar answered Oct 04 '22 13:10

Oak_3260548