5

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.

HappyTown
  • 6,036
  • 8
  • 38
  • 51
  • 3
    right click database name and then task generate scripts. – SqlZim Jan 27 '17 at 16:55
  • 2
    Right click on the database level -> Tasks -> Generate Scripts... allows you to choose multiple objects and has a lot more customisation of what is scripted. It's still a lot of clicking though! – Gareth Lyons Jan 27 '17 at 16:55
  • http://stackoverflow.com/questions/9429902/generate-script-in-sql-server-management-studio – SqlZim Jan 27 '17 at 16:55
  • 4
    Possible duplicate of [Generate script in SQL Server Management Studio](http://stackoverflow.com/questions/9429902/generate-script-in-sql-server-management-studio) – SqlZim Jan 27 '17 at 16:55
  • 2
    The Generate Script task will not include Indexes by default, you need to make sure the "script indexes" option is set to True. – pacreely Jan 27 '17 at 17:11

1 Answers1

10

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.

Oak_3260548
  • 1,882
  • 3
  • 23
  • 41