Skip to content

Instantly share code, notes, and snippets.

@Rotceh
Created July 19, 2017 09:24
Show Gist options
  • Select an option

  • Save Rotceh/4cd594bc81b9659a719720a728418fa7 to your computer and use it in GitHub Desktop.

Select an option

Save Rotceh/4cd594bc81b9659a719720a728418fa7 to your computer and use it in GitHub Desktop.
執行指定目錄內的.sql腳本
@echo off
rem 資料庫IP\資料庫執行個體名稱
set dbIp=stanley\SQL2014
rem 資料庫名稱
set dbName=TSQL2014
rem 登入帳號
set dbUsrAcc=ImDeveloper
rem 使用者密碼
set dbUsrPwd=Passw0rd
rem 整理完畢的SQL指令集資料夾位置
set batchFilePath="C:\TestDB\db_script\folder"
rem 程式開始執行
cd %batchFilePath%
FOR /f %%i IN ('DIR *.Sql /B') do call :RunScript %%i
GOTO :END
:RunScript
Echo Executing %1
sqlcmd -S %dbIp% -d %dbName% -U %dbUsrAcc% -P %dbUsrPwd% -i %1 >>view.log
Echo Completed %1
:END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment