I am sure these has been asked before but cannot find clear instruction how to create a
batch file lets call it “Update Database” this batch file should
Execute sql scripts located in different folders
Execute another 3 bat files.
Any quick examples how to do it?Never done it before
thanks a lot
EDITED
Can I do this?
:On Error exit
:r C:\myPath\MasterUpdateDatabase.bat
GO
SQLCMD -S (Local) -i C:\myPath\InsertUsername.sql
I get an error:
“GO” is not recognized as internal external command
Thanks for any input
It looks like you’re trying to use DOS commands to create a batch file that either (a) executes other batch files or (b) executes SQLCMD to run sql or a sql script.
Here are a couple examples all rolled into one. I’m using the DOS command
STARTwith the/WAITswitch, which will keep your original “master” batch file running in one window and execute the subsequent file or commands in a new window. That new window stays open until the script finished AND exits.Some of the
ECHOs probably aren’t required, but the script will talk back to you for now, a little.So, this is pretty simple in the sense that you’re just running the script. If you’re script1.bat has break points, you can return an error back to the main script and have it end immediately. I wasn’t clear if that was what you needed the master script to do.
Here is where did used the same START /WAIT to run SQLCMD, which in this case just returns results from the query. One thing to note here is that the
-Q(uppercase) runs the query and quits. If you use-q(lowercase) it will run the query and sit open in SQLCMD waiting for another query.And this is how you can run a sql script, which is what the
-idenotes, but I also didn’t run this in the START /WAIT as earlier. Not that you have to, but I wanted to show both examples. What this also shows is the-bwill end the batch process if your script returns an error, which is useful if you’re running multiple scripts that depend on success of the former(s).So, I assumed you were looking for a .bat or .cmd file that utilized SQLCMD. The example I provided is pretty basic, but hopefully it sets you on the right path.
OH! And remember that CTRL+C breaks a batch script in process.