项目需要执行许多SQL脚本文件,网上搜搜没发现特别合适的,花了点时间自已写了一个,主要分为两个批处理文件
main.bat 用关于查找所有需要执行的SQL文件
@echo on
for /r "C:\Documents and Settings\j1jiang\My Documents\sql scripts" %%i in (*.sql,*.prc) do call sub "%%i"
@echo off
替换 "C:\Documents and Settings\j1jiang\My Documents\sql scripts" 为需要的目录
sub.bat 调用sqlcmd.exe 执行SQL文件
echo Start execute %~1 >>result.txt
sqlcmd -U <user> -P <password> -S server\instanceName -d <dbname> -i %1 >>result.txt
echo execute sql %~1 completed! >>result.txt
echo -------------------------------------------------------------------------->>result.txt
来源:https://www.cnblogs.com/jjyjjyjjy/archive/2010/06/22/1762870.html