Using the SQLCMD in SQL 2005 Server
(Page 1 of 5 )
The SQLCMD lets you write SQL commands as well as T-SQL statements. It also has many other interesting features. This article explains the features of SQLCMD and shows you how to use them.
Introduction
SQLCMD is the preferred command-line utility in SQL 2005 Server although the OSQL utility can be used side by side with SQLCMD. OSQL is included for backward compatibility to deal with legacy scripts. ISQL has been discontinued.
SQLCMD can be run both in the DOS screen as well as in the MS SQL Server 2005 Management Studio's query editor in the SQLCMD mode. If you want to use scripting, which brings in features like color coding, parsing and executing scripts, and others, this must be enabled. Enabling SQLCMD allows you to write SQL Commands as well as T-SQL Statements. SQLCMD can be enabled in the query editor as shown in this picture,

or by going to tools it can be enabled by default as shown in the next picture.
One of the key advantages of this new command-line utility is its ability to set environmental variables and effectively use them in scripts and send output in XML if needed. This article does not on touch on all these interesting features and myriad other possibilities, but helps you in getting up and running. There are a number of rules that need to be observed in writing commands, but these will not be discussed either, and the reader is directed to BOL (Book On Line).

Next: On using SQLCMD from the command line >>
More MS SQL Server Articles
More By Jayaram Krishnaswamy