Generate SQL server scripts from command line?

Luke Sampson picture Luke Sampson · Aug 21, 2009 · Viewed 15.9k times · Source

In Microsoft SQL Server Management Studio 2008 there is a "Generate scripts..." option under the Tasks menu. I'm just wondering if this tool is available from the command line somehow?

Screenshot of Generate SQL Server Scripts Wizard

It looks similar to the sqlpubwiz.exe command line tool that was available for SQL Server 2005, but I can't find this executable anywhere in the SQL 2008 installation.

Answer

Remus Rusanu picture Remus Rusanu · Aug 21, 2009

The script generating options of Management Studio are just a wrapper around the SMO scripting capabilities. Simple scripts are obtained by using the Script() method on various SMO types. More complex scripts are created by the specialized Scripter class.

Command line tools can be easily created by using the SMO libraries.