Monday 24 July 2023

Batch script to run MS SQL server sql commands

 Hi, use "sqlcmd" utility in batch script run a set of sql commands/queries through batch script. 

Make sure to install the following odbc driver and command line utility
msodbcsql.msi and MsSqlCmdLnUtils.msi

runsql.bat
@echo off
sqlcmd -U "sa" -P "MyPassword#123" -S 11.123.4.56 -i "C:\SQLScripts\CleanUp.sql"
timeout /t 5 /nobreak
exit


CleanUp.sql
use abcDatabase
delete from accountTable where AccountId='123'


I hope you find this useful! If you like it, pls do subscribe my YouTube channel for automation or tech updates.

No comments:

Post a Comment