How to: Connect to SQL Azure Using sqlcmd
You can connect to Microsoft SQL Azure Database with the sqlcmd command prompt utility that is included with SQL Server. The sqlcmd utility lets you enter Transact-SQL statements, system procedures, and script files at the command prompt.
For general considerations about connecting to databases in SQL Azure, see Guidelines for Connecting to SQL Azure Database.
Connecting with sqlcmd
To connect to SQL Azure Database by using sqlcmd, append the SQL Azure server name to the login in the connection string by using the <login>@<server> notation. For example, if your login is login1 and the fully qualified name of the SQL Azure server is servername.database.windows.net, the username parameter of the connection string is: login1@servername. This restriction places limitations on the text you can choose for the login name. For more information, see CREATE LOGIN (SQL Azure Database).
Note |
|---|
| SQL Azure Database does not support the –z and –Z options used for changing users password with SQLCMD. To change login passwords, you can use the ALTER LOGIN (SQL Azure Database) after connecting to the master database. |
The following example shows how to connect to the master database in an SQL Azure server and then creates a sample database by using the Transact-SQL CREATE DATABASE (SQL Azure Database) statement:
C:\>sqlcmd -U <ProvideLogin@Server> -P <ProvidePassword> -S <ProvideServerName> -d master 1> CREATE DATABASE <ProvideDatabaseName>; 2> GO 1> QUIT
Next, you can connect to the previously created database directly and create a new table in the database by using the Transact-SQL CREATE TABLE (SQL Azure Database) statement:
C:\>sqlcmd -U <ProvideLogin@Server> -P <ProvidePassword> -S <ProvideServerName> -d <ProvideDatabaseName> 1> CREATE TABLE table1 (Col1 int primary key, Col2 varchar(20)); 2> GO 3> QUIT
Note |
|---|
| SQL Azure Database does not support heap tables. You must create a primary key or a clustered index. For more information, see General Guidelines and Limitations (SQL Azure Database). |
For more information about the sqlcmd Utility, see sqlcmd Utility in SQL Server Books Online.
See Also
Note