Skip to content

Latest commit

 

History

History
58 lines (38 loc) · 3.08 KB

File metadata and controls

58 lines (38 loc) · 3.08 KB
title Sqlcmd utility - 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 grrlgeek
ms.author jeschult
ms.reviewer maghan
ms.date 01/10/2023
ms.service sql
ms.subservice ssms
ms.topic conceptual
monikerRange >=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current

sqlcmd - Start the utility

[!INCLUDEsql-asdb-asdbmi-asa-pdw]

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.

Note

By default, [!INCLUDEssExpress] installs as the named instance sqlexpress.

Start the sqlcmd utility and connect to a default instance of SQL Server

  1. 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 [!INCLUDEssDEnoversion] before, you may have to configure SQL Server to accept connections.)

  2. At the command prompt, type sqlcmd.

  3. Press ENTER.

    You now have a trusted connection to the default instance of SQL Server that is running on your computer.

    1> is the sqlcmd prompt that specifies the line number. Each time you press ENTER, the number increases by one.

  4. To end the sqlcmd session, type EXIT at the sqlcmd prompt.

Start the sqlcmd utility and connect to a named instance of SQL Server

  1. Open a Command Prompt window, and type sqlcmd -SmyServer\instanceName. Replace myServer\instanceName with the name of the computer and the instance of SQL Server that you want to connect to.

  2. Press ENTER.

    The sqlcmd prompt (1>) indicates that you are connected to the specified instance of SQL Server.

    [!NOTE]
    Entered Transact-SQL statements are stored in a buffer. They are executed as a batch when the GO command is encountered.

Next steps

Learn more about sqlcmd and related concepts in the following articles: