views:

604

answers:

1

Is it possible to somehow use a .bat file to script the schema and/or content of a SQL Server database? I can do this via the wizard, but would like to streamline the creation of this file for source control purposes.

I would like to avoid the use of 3rd party tools - just limiting myself to the tools that come with SQL Server.

+2  A: 

There is a free tool called SubCommander that is a part of the open source SubSonic software. I have successfully used this tool myself to create both schema and data "dumps" each night.

You can script out your schema and data (and then version it in your favorite source control system) using SubCommander. Simply use the command "version" and tell SubCommander where to put the data:

sonic.exe version /out Scripts

This will output a script file (.sql) to the local scripts directory of your project

You can also try using the Microsoft SQL Server Database Publishing wizard, although i am not sure that you can use it in a bat file.

Espo