我使用 sqlcmd 实用程序获得了以下批处理脚本,用于执行许多文件中包含的sql脚本:
@echo off
setlocal enabledelayedexpansion
set /p servername=Enter DB Servername :
set /p dbname=Enter Database Name :
set /p spath=Enter Script Path :
set /p usr=Enter the username :
set /p pw=Enter the password :
set hr=%time:~0,2%
if "%hr:~0,1%" equ " " set hr=0%hr:~1,1%
set logfilepath= %spath%\output_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%hr%%time:~3,2%%time:~6,2%.log
set cmd='dir "%spath%\*.sql" /b'
FOR /f "delims=" %%f IN (%cmd%) DO (
echo ******PROCESSING %%f FILE******
echo ******PROCESSING %%f FILE****** >> %logfilepath%
SQLCMD -S%servername% -U%usr% -P%pw% -d%dbname% -s" -i%%f -b >> %logfilepath%
IF !ERRORLEVEL! NEQ 0 GOTO :OnError
)
GOTO :Success
当我运行此脚本时出现“1>”提示将等待命令。我能理解出了什么问题。
非常感谢
答案 0 :(得分:2)
您正在启动SQLCMD并且没有按照您的意愿行事。对于初学者我会改变这一行
SQLCMD -S%servername% -U%usr% -P%pw% -d%dbname% -s" -i%%f -b >> %logfilepath%
到
SQLCMD -S %servername% -U %usr% -P "%pw%" -d%dbname% -s ^" -i "%%f" -b >> "%logfilepath%"