SQL Azure: Creating & dropping a database with SQLCMD

Once you've your server allocated via SQL Azure Portal you can create and drop databases from your desktop's command line using sqlcmd.exe. This can be handy for clean slate testing where you want to create a database from scratch, unload a schema and then do some testing in a repeatable way.First, you need to construct […]

Once you've your server allocated via SQL Azure Portal you can create and drop databases from your desktop's command line using sqlcmd.exe. This can be handy for clean slate testing where you want to create a database from scratch, unload a schema and then do some testing in a repeatable way.

First, you need to construct a .sql file that contain Transact-SQL command to create your database, it looks: CREATE DATABASE Test. This'll create you a 1 GigaByte database, default size. There should be no other Transact-SQL statements in this .sql file. More on MSDN.

To execute from command line where file is named CreateDatabase.sql, use this command: sqlcmd -SyourSeverdatabase.windows.net -UyouLogin@yourServer -PyourPassword -dmaster -i –N CreateDatabase.sql. "user name needs to be in the form: yourLogin@yourServer, where login is the admin login for server on SQL Azure. You can get this information directly from SQL Azure portal. Notice that database targeted is master.

Dropping a database looks like: DROP DATABASE Test. More on MSDN. To execute from command line where file is named DropDatabase.sql, use this command: sqlcmd -SyourSeverdatabase.windows.net -UyouLogin@yourServer -PyourPassword -dmaster -i –N DropDatabase.sql.

[Source]