JavaScript Editor Ajax toolkit     Ajax tutorials 



Main Page

Previous Page
Next Page

2.8. New Command-Line Utilities

SQL Server 2005 introduces the new command-line utilities described in Table 2-2.

Table 2-2. New SQL Server command-line utilities

Utility

Description

sqlcmd

Executes T-SQL statements, system procedures, and script files from the command prompt. The sqlcmd utility is described further later in this section.

sqlwb

Launches SQL Server Management Studio from the command prompt.

profiler90

Launches SQL Server Profiler from the command prompt.

dta

Launches Database Engine Tuning Advisor from the command prompt.

dtexec

Used to configure and execute an SSIS package loaded from a database, the SSIS package store, or the file system.

dtutil

Used to manage and verify existence of an SSIS package stored in the SQL Server msdb database, the SSIS package store, or the file system.

tablediff

Used to compare the data in two tables for nonconvergence.


2.8.1.

2.8.1.1. SQL Server command-line tool (sqlcmd utility)

The SQL Server command-line tool lets you execute T-SQL statements, system procedures, and script files from the command prompt. The sqlcmd utility replaces the osql and isql utilities. sqlcmd uses OLE DB to communicate with the SQL Server Database Engine instead of using ODBC or DB-Library APIs.

Regular command mode in SQL Server Management Studio uses the .NET SqlClient provider for execution in regular and command mode, whereas sqlcmd uses the OLE DB provider. As a result, it is possible to get different results when executing the same query, because different default options might apply.


The following example connects to the default instance of SQL Server and executes a query against the AdventureWorks database. Open a Command Prompt dialog box (Start All Programs Accessories Command Prompt) and execute the following command:

    sqlcmd -q "SELECT TOP 3 ContactID, FirstName, LastName FROM
      AdventureWorks.Person.Contact"

The console output is shown in Figure 2-19.

The -q switch executes the specified query. The -? switch returns information about all switches for the sqlcmd utility. For a complete overview of the sqlcmd utility and its switches, see Microsoft SQL Server 2005 Books Online.

Figure 2-19. sqlcmd example


Alternatively, you can start sqlcmd and execute the preceding query in a batch with the following commands:

    sqlcmd
    SELECT TOP 3 ContactID, FirstName, LastName FROM AdventureWorks.Person.Contact"
    GO

Figure 2-20 shows the sqlcmd batch.

Figure 2-20. SqlCmd batch example


The QUIT or EXIT command exits sqlcmd batch mode.


Previous Page
Next Page


JavaScript Editor Ajax toolkit     Ajax tutorials 
R7