Exportera (0) Skriv ut
Visa allt
EN
Det här innehållet finns inte tillgängligt på ditt språk men här finns den engelska versionen,

How to: Connect to Azure SQL Database Using sqlcmd

Updated: December 6, 2013

You can connect to Microsoft Microsoft Azure SQL 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 Azure SQL Database, see Guidelines for Connecting to Azure SQL Database.

Connecting with sqlcmd

To connect to Microsoft Azure SQL Database by using sqlcmd, append the Azure SQL Database 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 Azure SQL Database 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 (Azure SQL Database).

noteNote
Microsoft Azure SQL 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 (Azure SQL Database) after connecting to the master database.

The following example shows how to connect to the master database in an Azure SQL Database server and then creates a sample database by using the Transact-SQL CREATE DATABASE (Azure SQL 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 (Azure SQL 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
noteNote
Microsoft Azure SQL Database does not support heap tables. You must create a primary key or a clustered index. For more information, see Azure SQL Database General Guidelines and Limitations.

For more information about the sqlcmd Utility, see sqlcmd Utility in SQL Server Books Online.

See Also

Gruppinnehåll

Lägg till
Visa:
© 2014 Microsoft