Eksportér (0) Udskriv
Udvid alt
EN
Dette indhold er ikke tilgængeligt på dit sprog, men her er den engelske version.

How to: Connect to Azure SQL Database Using sqlcmd

Updated: November 24, 2014

You can connect to Microsoft Azure SQL Database with the sqlcmd command prompt utility that is included with SQL Server or the Microsoft Command Line Utilities 11 for SQL Server. The sqlcmd utility lets you enter Transact-SQL statements, system procedures, and script files at the command prompt.

For general guidelines about connecting to databases in Azure SQL Database, see Guidelines for Connecting to Azure SQL Database Programmatically.

To connect to Microsoft Azure SQL Database using sqlcmd

  • Open the command prompt and enter sqlcmd followed by the connection string for your Azure SQL Database master database. For example, sqlcmd -U login1@servername.database.windows.net -P passw0rd! -S servername.database.windows.net -d master.

  • The username value uses <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.database.windows.net. For more information about the other options, see sqlcmd.

To create a database and table using sqlcmd

  1. To connect to the master database in an Azure SQL Database server and then create a sample database, use the Transact-SQL CREATE DATABASE statement:

    C:\>sqlcmd -U <ProvideLogin@Server> -P <ProvidePassword> -S <ProvideServerName> -d master
    1> CREATE DATABASE <ProvideDatabaseName>;
    2> GO
    1> QUIT
    
  2. 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 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
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 statement after connecting to the master database.

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.

See Also

Fællesskabsindhold

Tilføj
Vis:
© 2014 Microsoft