SQLCMD and SQL Azure

I’ve seen several questions on forums over whether or not you can use SQLCMD with your SQL Azure instance.  Well, I’m here to say yes you can!  You can even create databases using the command line.

Create a .sql file with a script that creates your database, then save the file.


Then drop back to command line and use the following command:

sqlcmd -SyourInstanceName.windows.net -Uyou@domain.com -PyourPassword -dmaster -i –N CreateDatabase.sql

The server is whatever your SQL Azure instance name is, your login and password should be the login and password you have set up to access your Azure instance. I would like you to notice you’re connecting to the master database, just as you would in a local SQL instance. Run this command, and you have your database. If you wanted to drop a database, just change out the script file to one that points to a DROP DATABASE command.

If you want to run any other script from SQLCMD, just make sure you update master to the database that that contains the objects you’re going to reference in your script. Just remember, you cannot use GO databaseName with SQL Azure. Pretty easy stuff, right?

If you have any questions or concerns with SQL command and SQL Azure, let me know! I’m here to help!

By Shannon Lowder

Shannon Lowder is the Database Engineer you've been looking for! Look no further for expertise in: Business Analysis to gather the business requirements for the database; Database Architecting to design the logical design of the database; Database Development to actually build the objects needed by the business logic; finally, Database Administration to keep the database running in top form, and making sure there is a disaster recovery plan.

Leave a comment

Your email address will not be published. Required fields are marked *