Thursday, January 21, 2010

Windows batch file that accepts user input to execute set of sql files

Last week, I was trying to get Performance Dashboard deployed across some 80+ sql instances which requires running a couple of scripts against each of those sql instances. Also there are separate set of scripts for instances running on 2005 and 2008. So I came up with this small windows batch file that which takes user input prompting the user to input the server name and then the version. Based on the server name it uses sqlcmd utility to connect to the instance and run the script from either folder called '2005' or '2008' which is again based on the version number input by the user.

@echo off
set /p servername= Please enter the servername:
set /p version= Please enter the version number 2000 or 2005 or 2008:
if %version%==2000 (@echo cannot run performance dashboard against 2000 instance)
if %version%==2005 (sqlcmd -E -S %servername% -i "C:\batch files\perf_dashboard\2005\setup.sql" -b
sqlcmd -E -S %servername% -i "C:\batch files\perf_dashboard\2005\fix.sql" -b)
if %version%==2008 (sqlcmd -E -S %servername% -i "C:\batch files\perf_dashboard\2008\setup.sql" -b
sqlcmd -E -S %servername% -i "C:\batch files\perf_dashboard\2008\fix.sql" -b)

No comments:

Post a Comment

Display the list of indexes and columns for a given table

You might find yourself in a situation where you have to analyze the indexes for a given table and want to know which columns are part of wh...