Reputation: 1496
I have to execute bulk of scripts on a database server, i am able to execute it with the help of batch but This database server having multiple databases,so for every database i am writing below mentioned script- EX-
for database name1-
for %%G in (*.sql) do sqlcmd /S [Server] /d [A] -E -i"%%G" pause
for database name2-
for %%G in (*.sql) do sqlcmd /S [Server] /d [B] -E -i"%%G" pause
is there any way so that i don't have to write this .bat file for every database name?i want to write single script which works for all the databases...
Upvotes: 2
Views: 296
Reputation: 944
You could change your script to be:
for %%G in (*.sql) do sqlcmd /S %1 /d %2 -E -i"%%G" pause
then pass in the server and database name when launching the bash script. For example, if your script was called "myscript.bat", then you could launch it from command line via
> myscript.bat server name
Upvotes: 1