| title | Start the sqlcmd Utility | |
|---|---|---|
| description | Learn how to start the sqlcmd utility, which lets you enter Transact-SQL statements, system procedures, and script files, in SQLCMD mode or in scripts and jobs. | |
| author | dlevy-msft | |
| ms.author | dlevy | |
| ms.reviewer | randolphwest | |
| ms.date | 07/02/2025 | |
| ms.service | sql | |
| ms.subservice | tools-other | |
| ms.topic | how-to | |
| ms.collection |
|
|
| ms.custom |
|
|
| monikerRange | >=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric-sqldb |
[!INCLUDE SQL Server Azure SQL Database Azure SQL Managed Instance Azure Synapse Analytics PDW FabricSQLDB]
The sqlcmd utility lets you enter Transact-SQL statements, system procedures, and script files at the command prompt, in SQLCMD mode in SQL Server Management Studio, and in a Windows script file or in an operating system (Cmd.exe) job step of a SQL Server Agent job.
Note
Windows Authentication is the default authentication mode for sqlcmd. To use SQL Server Authentication, you must specify a user name and password by using the -U and -P options.
By default, [!INCLUDE ssExpress] installs as the named instance sqlexpress.
-
On the Start menu, select Run. In the Open box type cmd, and then select OK to open a Command Prompt window. (If you haven't connected to this instance of the [!INCLUDE ssDEnoversion] before, you might have to configure [!INCLUDE ssnoversion-md] to accept connections.)
-
At the command prompt, type
sqlcmd. -
Press
ENTER.You now have a trusted connection to the default instance of [!INCLUDE ssnoversion-md] that is running on your computer.
1>is the sqlcmd prompt that specifies the line number. Each time you pressENTER, the number increases by one. -
To end the sqlcmd session, type
EXITat the sqlcmd prompt.
-
Open a Command Prompt window, and type
sqlcmd -S<myServer\instanceName>. Replace<myServer\instanceName>with the name of the computer and the instance of the [!INCLUDE ssdenoversion-md] that you want to connect to. -
Press
ENTER.The sqlcmd prompt (
1>) indicates that you're connected to the specified instance of [!INCLUDE ssnoversion-md].The Transact-SQL statements you enter are stored in a buffer. They're executed as a batch when the
GOcommand is encountered.