Tutorial: sqlcmd Utility
This tutorial provides a brief introduction to the sqlcmd utility for users who do not have experience using a command-line utility.
You can use the sqlcmd utility, a Microsoft Win32 command prompt utility, to run ad hoc Transact-SQL statements and scripts. To use sqlcmd interactively, or to build script files that you can run by using sqlcmd, you must understand Transact-SQL. The sqlcmd utility typically is used in these ways:
In the sqlcmd environment, you can interactively enter Transact-SQL statements the same way you enter them when you are working at the command prompt. The results are displayed in the Command Prompt window, unless you choose otherwise. Later in the tutorial you will learn how to send result sets to output files.
You can submit a sqlcmd job either by specifying a single Transact-SQL statement to execute or by pointing the utility to a script file that contains Transact-SQL statements to execute. sqlcmd can connect to earlier versions of SQL Server.
What You Will Learn
In this tutorial, you will learn how to connect to a named instance of Microsoft SQL Server by using sqlcmd. You will also learn how to run a Transact-SQL script from a file that generates a list of Adventure Works Cycles employee names and addresses and then store those names and addresses in a text file.
Lesson 1: Starting sqlcmd
In this lesson, you will learn how to start sqlcmd and use some of its common options.
Lesson 2: Running Transact-SQL Script Files by Using sqlcmd
In this lesson, you will learn how to use sqlcmd to run Transact-SQL code that is stored in script files.
When you are reviewing tutorials, we recommend that you add next and previous buttons to the document viewer toolbar. For more information, see Adding Next and Previous Buttons to Help.