cls
rem Usage : DatabaseScripts <
echo Welcome to Deployment Script
SET SOURCEFOLDER=%1
SET UserName=%2
SET Password=%3
SET ServerName=%4
IF /I "%SOURCEFOLDER%" == "" (
ECHO "PATH TO SOURCE FOLDER NOT SPECIFIED".
GOTO QUIT
)
IF /I "%UserName%" == "" (
ECHO "User Name NOT SPECIFIED".
GOTO QUIT
)
IF /I "%Password%" == "" (
ECHO "Password NOT SPECIFIED".
GOTO QUIT
)
IF /I "%ServerName%" == "" (
ECHO "Server Name NOT SPECIFIED".
GOTO QUIT
)
IF NOT EXIST "%SOURCEFOLDER%" (
ECHO SOURCE FOLDER "%SOURCEFOLDER%" DOES NOT EXIST.
GOTO QUIT
)
REM pass database names in for loop
FOR %%D IN (db1 db2 db3 db4) DO (
sqlcmd -S %ServerName% -U %UserName% -P %Password% -d %%D -i %SOURCEFOLDER%\Deployment.sql -o %SOURCEFOLDER%\deploy_log_%%D.txt
)
ECHO "Deployed the script successfully"
pause
:QUIT
The above batch file accepts below parameters
- SOURCEFOLDER: Folder location where deployment script is located. It assumes that file name is Deployment.sql.
- UserName: UserName for the database
- Password: Password for the database
- ServerName: Database server Name
After execution of the scripts, it will create log file for each database. Log files will be created in directory where the database deployment script is located.
Sqlcmd is a command line tool which can be used to deploy scripts in by reading from file.
No comments:
Post a Comment