Need help to write bat file that execute sql scripts in (sql server 2008 and another 3 files.? -


I'm sure they were asked before but no instructions are available for how to create a batch file "Update Database" This batch file

execute SQL scripts located in different folders Execute other 3 bit files.

How to do a quick example? Thanks a long time ago

edit

Can I do this?

 : When the error is over: go to rc: \ myPath \ MasterUpdateDatabase.bat SQLCMD -S (local) -i C: \ MyPath \ InsertUsername.sql  
< P> I get an error:

"Geo" has not been recognized as an internal external command

Thanks for any input

It seems that you are trying to use the DOS command, a batch file that is (A) Executes other batch files or (b) Sqlmmd to s Runs to run QL or SQL script

I am using the START switch using the / WAIT switch, which will keep your original "master" batch file in a window. And will implement later files or commands A new window is open in that new window until the script ends and exits.

Some ECHO s are probably not necessary, but the script will now talk back for you, a little bit.

  @echo off  

Therefore, it is very easy in this sense that you are running the script now. If you are 1.bat the script then there are break points, you can return an error back to the main script and it can end it immediately. I was not clear whether you needed a master script to do this .

  echo start database updates echo Echoing echoing script 1 Start resonance / wait C: \ path \ to \ your \ script1.bat echo If there was a problem, please break here. Stop Echo Echoing Script 2 Start / Resume C: \ path \ to \ your \ script2.bat Echo: If there is a problem, please break here. Stop  

Here the START / WAIT was used to run SQLMMD, which in this case results from just the query. Here's a note to note that -Q (uppercase) runs queries and resigns. If you use -q (lowercase), it will run the query and is waiting for another query in SQLCMD.

  echo execution of SQLMMD: "Select the top 100 from sys.objects" Start / wait sqlcmd -S (local) -Q "Select the top 100 from sys.objects"  

And how is it that you can run a SQL script, which indicates -i , but I did not run it in the Start / WT as before. That's what you have to do, but I wanted to show both examples. It also shows that if your script returns an error, -b will end the process of batch, which is useful, if you are running multiple scripts that are dependent on earlier success.

  echo execute SQLMMD from an (-i) nput file: sqlcmd -S (local) -i C: \ path \ to \ your \ script.sql -b echo resize update Stop End  

Therefore, I assume that you were searching for a .bat or .cmd file that used SQLCMD. The example I have given is very basic, but hopefully it will set you on the right track.

Oh! And remember that CTRL + C breaks a batch script in the process.


Comments