Lesson 1: Starting sqlcmd

To begin using sqlcmd, you must first launch the utility and connect to an instance of SQL Server. You can connect to either a default or named instance. The first step is to start the sqlcmd utility.

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, SQL Server 2005 Express Edition installs as the named instance sqlexpress.

If you have not connected to this instance of the SQL Server Database Engine before, you may have to configure SQL Server to accept connections. For more information, see the tutorial Getting Started with the Database Engine.

  1. On the Start menu click Run. In the Open box type cmd, and then click OK to open a Command Prompt window.

  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.

  1. Open a Command Prompt window, and type sqlcmd -S myServer\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.

Community Additions