In SSMS when I click on the database "Tasks -> Generate Scripts", I get an output script.
How do I do the same with a non-graphical tool?
In SSMS when I click on the database "Tasks -> Generate Scripts", I get an output script. How do I do the same with a non-graphical tool? |
|||||
|
The graphical tool is just a wrapper around the SMO classes that actually implement scripting, like the Scripter class. There is an example of scripting all tables in a database with SMO in MSDN: Scripting:
There are many more examples how to use it on various other sites. |
|||
|
You can use powershell to do this. An example here for scripting tables. http://www.simple-talk.com/sql/sql-tools/using-powershell-to-generate-table-creation-scripts/ I'm guessing that it should be possible to extend for other types of database object. Edit Just noticed that the title says data as well as schema. I'm not aware of anything free that does this from the command line. Redgate SQL Compare Suite is automatable from the command line if you buy the right version or you could write an application/power shell script to do it. |
||||
|
For the data, you can use a bulk export utility called I don't know of any SQL Server supplied utility that would create SQL scripts with INSERT statements as the SQL Server Management Studio does. |
|||
|
You can script schema and data using the SQL Server publishing wizard. This can be done from the command line. Version 1.4 is the one you want it's bundled with Visual Studio as of version 2008 and also with SQL Server 2008. You can find it in Program Files/Microsoft SQL server/90/Tools/Publishing/1.4/SqlPubWiz I beleive it's also a project on CodePlex. Type SQlPubWiz /? to see command line options |
||||
|