JDBC Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 2.11

SQLCMD SQL Server Command Line Tool

This section describes how to SQL Server command line tool - SQLCMD.

Before you start using Java programs to interact with SQL Server databases, you should learn some SQL Server client tools to run SQL statements on the SQL Server. SQLCMD, Query Analyzer, and Management Studio are good client tools to use. But SQLCMD comes with SQL Server 2005 Express Edition installation, and is ready to use.

This tutorial shows you how to use SQLCMD, a command line client tool, to run SQL statements on your local SQL Server databases.

When "sqlcmd" is started and connected to a SQL Server, it will you to enter statements or commands. You can enter one or more statements in one or more lines to form a Transact-SQL statement batch.

To end a batch of statements and send it to the SQL Server for execution, you need to enter the GO command. The following "sqlcmd" tutorial session sends two batches to the SQL Server:

C:\>sqlcmd -S localhost -U sa -P HerongYang
1> SELECT DB_NAME();
2> GO

------------------------
master

(1 rows affected)

1>QUIT
C:\

As you can see, I logged in to the server as "sa" with no problem. The "GO" command sends one SQL statement to the server. The returning output telling me that I was connected to the "master" database.

Sections in This Chapter

Downloading Microsoft SQL Server 2005 Express Edition

Installing Microsoft SQL Server 2005 Express Edition

SQLCMD SQL Server Command Line Tool

Installing AdventureWorksLT Sample Database

Dr. Herong Yang, updated in 2007
SQLCMD SQL Server Command Line Tool