Microsoft SQL Server

SQLCMD

Remarks#

You either need to be in the path where SQLCMD.exe exists or add it to your PATH environment variable.

SQLCMD.exe called from a batch file or command line

echo off

cls

sqlcmd.exe -S "your server name" -U "sql user name" -P "sql password" -d "name of databse" -Q "here you may write your query/stored procedure"

Batch files like these can be used to automate tasks, for example to make backups of databases at a specified time (can be scheduled with Task Scheduler) for a SQL Server Express version where Agent Jobs can’t be used.


This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow