The sqlcmd utility lets you enter Transact-SQL statements, system procedures, and script files through a variety of available modes:
- At the command prompt.
- In Query Editor in SQLCMD mode.
- In a Windows script file.
- In an operating system (Cmd.exe) job step of a SQL Server Agent job.
The utility uses ODBC to execute Transact-SQL batches.
Run sql from command line.
ECHO Running script01.sql... cmd /c sqlcmd -b -i script01.sql -S localhost -d master >script01.log IF [%ERRORLEVEL%] NEQ  GOTO ERROR
SQLCMD is installed by default if you install SQL Server. If SQL Server is not installed, you will need to install C++ redistributor, ODBC, and SQL Util for SQLCMD.
-b (terminate batch job if there is an error)