Connect to a dedicated SQL pool in Azure Synapse Analytics with sqlcmd

Use the [sqlcmd][sqlcmd] command-line utility to connect to and query a dedicated SQL pool.

1. Connect

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 -I

To 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 -I

Note

You need to enable Microsoft Entra authentication to authenticate using Microsoft Entra ID.

2. Query

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> QUIT

These 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.out

Next steps

For more about details about the options available in sqlcmd, see sqlcmd documentation.