2

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...

1
  • so is [server] and [A]/[B] actual values? Commented Mar 7, 2013 at 17:39

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

4 Comments

Can you please have a look on my updated question? actually database name doesn't follow any pattern..
I edited my answer to reflect what I believe you are trying to represent, however see my comment on you question.
thanks,it's working fine.i do have one more query..normally if i have to execute any folder's files i have to put my batch file there and there are many subfolders, so i have to paste my bat file in every folder..is there a way so that i have to place my bat file only at one location and it executes the subfolders files?
You should create a seperate question on here for that. Unfortunately im not extremely versed in batch scripting, so i cant really answer that question, but if my post answered the question in this thread, please marke it as the correct answer and upvote it apropriately. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.