Chapter 6. Inside SQLCMD Query Tools
SQLCMD is a new tool developed for SQL Server 2005. Its main purpose is to let the user connect to a SQL Server Database Engine Instance directly from the command line and run ad hoc T-SQL statements and scripts. One of the original design goals of SQLCMD was backward compatibility with the deprecated OSQL tool, to simplify migration. SQLCMD supports most of the legacy command line options supported by OSQL, plus some new ones. Aside from the command line options, SQLCMD also introduces many other useful features to make implementing some core DBA scenarios extremely efficient.
Tips and Tricks
SQLCMD uses the OLE-DB provider, whereas OSQL used the ODBC provider. Although many of the command line options look the same, the underlying technology of the two tools is radically different, so some differences in behavior (especially in the returned provider error codes) are to be expected.
This chapter covers all the SQLCMD options, special commands supported by the tool, and scripting variables. It also describes typical usage scenarios of SQLCMD for miscellaneous database management operations. To simplify authoring and execution, SQL Server Management Studio Query Editor has support for SQLCMD scripts. Later in this chapter you will find discussion on how to leverage this feature, as well.
|