| title | Connect with sqlcmd | |
|---|---|---|
| description | Use sqlcmd command-line utility to connect to and query a dedicated SQL pool in Azure Synapse Analytics. | |
| author | joannapea | |
| ms.author | joanpo | |
| ms.date | 04/17/2018 | |
| ms.service | azure-synapse-analytics | |
| ms.subservice | sql-dw | |
| ms.topic | quickstart | |
| ms.custom |
|
[!div class="op_single_selector"]
Use the [sqlcmd][sqlcmd] command-line utility to connect to and query a dedicated SQL pool.
To get started with [sqlcmd][sqlcmd], open the command prompt and enter sqlcmd followed by the connection string for your dedicated SQL pool. The connection string requires the following parameters:
- Server (-S): Server in the form
<Server Name>.database.windows.net - Database (-d): dedicated SQL pool name.
- Enable Quoted Identifiers (-I): Quoted identifiers must be enabled to connect to a dedicated SQL pool instance.
To use SQL Server Authentication, you need to add the username/password parameters:
- User (-U): Server user in the form
<User> - Password (-P): Password associated with the user.
For example, your connection string might look like the following:
C:\>sqlcmd -S MySqlDw.database.windows.net -d Adventure_Works -U myuser -P myP@ssword -ITo use Microsoft Entra integrated authentication, you need to add the Microsoft Entra parameters:
- Microsoft Entra authentication (-G): use Microsoft Entra ID for authentication
For example, your connection string might look like the following:
C:\>sqlcmd -S MySqlDw.database.windows.net -d Adventure_Works -G -INote
You need to enable Microsoft Entra authentication to authenticate using Microsoft Entra ID.
After connection, you can issue any supported Transact-SQL statements against the instance. In this example, queries are submitted in interactive mode.
C:\>sqlcmd -S MySqlDw.database.windows.net -d Adventure_Works -U myuser -P myP@ssword -I
1> SELECT name FROM sys.tables;
2> GO
3> QUITThese next examples show how you can run your queries in batch mode using the -Q option or piping your SQL to sqlcmd.
sqlcmd -S MySqlDw.database.windows.net -d Adventure_Works -U myuser -P myP@ssword -I -Q "SELECT name FROM sys.tables;""SELECT name FROM sys.tables;" | sqlcmd -S MySqlDw.database.windows.net -d Adventure_Works -U myuser -P myP@ssword -I > .\tables.outFor more about details about the options available in sqlcmd, see sqlcmd documentation.