I got tired of having to execute multiple scripts one at a time from
 my testing server to my production server. So I decided to create a
 batch routine that utilizes the command line routine OSQL. All you
 have to do to use it is place the batch file in a directory containing
 your SQL scripts and execute the batch file. I have placed in the
 command the argument to print a result file for each sql script. If
 you need your SQL scripts run in a particular order simply rename them
 accordingly. i.e. 001_updatecustomer.sql, 002_update_sp.sql
 enjoy
 REM #############################################
 REM Author: Joe Ocampo
 REM Date: 04/17/2004
 REM Version: 1.0.1
 REM #############################################
 REM You must execute the script from the SQL server itself
 REM and you must use the SA login or the DBO login of the
 REM target database.
 REM #############################################
 SET login=sa
 SET password=password
 SET server=local
 SET database=pubs
 for %%a in (*.sql) do osql -d %database% -U %login% -P %password% -i
 %%a -o %%a_result.txtJoe wrote:
> I got tired of having to execute multiple scripts one at a time from
> my testing server to my production server. So I decided to create a
> batch routine that utilizes the command line routine OSQL. All you
> have to do to use it is place the batch file in a directory containing
> your SQL scripts and execute the batch file. I have placed in the
> command the argument to print a result file for each sql script. If
> you need your SQL scripts run in a particular order simply rename them
> accordingly. i.e. 001_updatecustomer.sql, 002_update_sp.sql
Exceedingly simple, but incredibly useful, and something that I was going to
have to write myself pretty soon - thanks.
John.
 
No comments:
Post a Comment