SQLCmd is a command line tool that allows you to enter T-SQL sentences or script files by connecting to the SQL Server instance using OLE DB. SQLCmd is the replacement for the previous osql command.
To start the SQLCmd utility, you should launch SQLCmd from the command line. You can use the default SQL Server instance or connect to a named SQL Server instance.
From the Start menu, click Run. In the Open textbox, type cmd and click OK.
In the command prompt, type sqlcmd and press Enter.
You will enter the SQLCmd shell and observe a 1> prompt.
Type Select name from sys.databases and press Enter.
Type Go and press Enter. The result will be displayed.
Type Exit and press Enter to quit SQLCmd.
If you want to connect to a named instance, you should use the S input parameter and specify the instance name in the Server\Instance format. You can view all input parameters by executing SQLCmd /?, as shown in Figure 3-20.
You can use SQLCmd to execute script files from the command line, which allows you to schedule scripts outside the SQL Server instance.
From the Start menu, click Run.
In the Open textbox, type cmd and click OK.
In the command prompt, type sqlcmd i < path >\Ch03\SQLCmd.sql (replace <path> with the path in which you installed the sample files).
Press Enter. A list of product names is displayed.