The release of Visual Studio Team System Database Edition GDR version includes a very powerful tool to import and deploy database schemas from boxes where Visual Studio is not installed. The tool is a command line utility capable of:
The utility is called VSDBCMD.exe and is installed to the default location of %\ProgramFiles%\Microsoft Visual Studio 9.0\VSTSDB\Deploy when you install the GDR release.
VSDBCMD comes in real handy when you need to automate your database deployments. You can use it to deploy database changes to environments you can not connect to from your desktop by running the utility locally from a flash drive or installer. You can also run the utility while on a customer site to import a database schema into a dbschema file that you can later use to compare against your database project or reference its schema. There are numerous scenarios where the utility can simplify working with remote databases.
To use the utility on a box without VSTSDB installed to import or generate script you need the following:
To use the utility on a box without VSTSDB installed to deploy you also need the SQL Batch Parser which is installed with:
Here is an example of using VSDBCMD to import the Northwind Database into a dbschema file; then deploy the dbschema file as a new database back to the same database instance; and finally generating a deployment script based on the imported dbschema file.
ECHO OFFECHO "Importing Database Schema..."vsdbcmd.exe /a:Import /cs:"Server=MYSQLSERVER\SQL2k8;Integrated Security=true;Pooling=false;Initial Catalog=Northwind;" /dsp:Sql /model:"NorthwindVSDBCMD.dbschema"PAUSEECHO "Deploying Database Schema..."vsdbcmd.exe /a:Deploy /cs:"Server=MYSQLSERVER\SQL2k8;Integrated Security=true;Pooling=false" /dsp:Sql /dd+ /model:"NorthwindVSDBCMD.dbschema" /p:TargetDatabase="NewNorthWind"PAUSEECHO "Generating Database Deployment Script..."vsdbcmd.exe /a:Deploy /cs:"Server=MYSQLSERVER\SQL2k8;Integrated Security=true;Pooling=false" /dsp:Sql /script:CreateNorthWindDB.sql /model:"NorthwindVSDBCMD.dbschema" /p:TargetDatabase="NorthWindFromScript"PAUSE
To see the list of available options based on the DSP and Action you can execute:
vsdbcmd.exe /dsp:Sql /?PAUSEvsdbcmd.exe /a:Import /? /dsp:Sql /cs:"MYSQLSERVER\SQL2k8;Integrated Security=true;Pooling=false;Initial Catalog=Northwind;"PAUSEvsdbcmd.exe /a:Deploy /? /dsp:Sql /cs:"MYSQLSERVER\SQL2k8;Integrated Security=true;Pooling=false;Initial Catalog=Northwind;" PAUSE