Skip to content

Instantly share code, notes, and snippets.

@ettingshausen
Last active May 19, 2022 18:04
Show Gist options
  • Save ettingshausen/9729e2e0be33beb158ff976d0458003c to your computer and use it in GitHub Desktop.
Save ettingshausen/9729e2e0be33beb158ff976d0458003c to your computer and use it in GitHub Desktop.
execute sql script via sqlcmd
:: Name: sql_execute.cmd
:: Purpose: execute script.sql via sqlcmd
:: Author: ettingshausen
:: Revision: 2018/3/1 - initial version
::
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SET parent=%~dp0
SET interactive=0
SET sql_script="%parent%%1"
ECHO %COMSPEC% | FINDSTR /L %CMDCMDLINE% >NUL 2>&1
IF %ERRORLEVEL% == 0 SET interactive=1
SET server="localhost"
SET username="sa"
SET password="root"
:: execute script
sqlcmd -S %server% -U %username% -P %password% -i %sql_script%
IF "%interactive%"=="0" PAUSE
EXIT /B %ERRORLEVEL%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment