I get a zipped file of sql dumps everyday. I unzip it, and then run this script everyday using a task scheduler to update the database.
#echo off
ECHO %USERNAME% started the batch process at %TIME% >output.txt
for %%f in (C:\Users\Desktop\Crash\*.sql) do (
sqlcmd.exe -S HUTRC1-HP -U sa -P hutrc#2121 -d test -i %%f >>output.txt)
exit
The database doesn't however get updated all the time. Let's just say it is not very reliable. There are some days when it is current, and other days when it's not current. Can't explain why. Is there more efficient script to update the database with? Preferably in powershell.
Creating an SSIS package will help you and achieve all that you want with better error handling.
There are multiple articles out there and a bunch of youtube videos. A youtube video can help you accomplish what you need in no time. Here are some articles that i quickly got off of msdn.
How to create an SSIS package.
How to unzip files in SSIS package without any C# knowledge
How to automate an SSIS package.
Hope this helps.
Related
I am trying to Run a teradata SQL script via a batch script and export the details.
I have managed to execute the whole thing in DOS which is great
Im just not sure how to package it up
Below is my very average attempt. COuld anyone point me in the right direction?
The SQL is SELECT DATE
#title Optional Title
#echo off
C:\'Program Files (x86)'\Teradata\Client\15.00\Teradata SQL Assistant\
Sqla -c DB_NAME -f "C:\Temp\test.sql" -e "c:\Temp\test_output.log"
Thanks
I found the answer on another different question on Stack Overflow
How do I execute cmd commands through a batch file?
This basically does what i need or at least points me in the correct direction
Thank you for your time
I am really new to Batch and DB2 and got little time to explore much about them. I just want to know how it is possible for a batch program to pass a value/s to a db2 file so I can manipulate my database.
I found several suggestions but none of them worked. Here's my batch codes so far:
Rem This is db2execute.bat
#echo off
db2cmd -c -w -i db2 -tf INSERT.db2 id=1
PAUSE
My .db2 file on the other hand:
CONNECT TO SAMPLEDB;
INSERT INTO TB1 VALUES('$(ID)');
I would really appreciate some kind help. Thanks.
At the present time, in the shipping versions of Db2-LUW, the CLP (command line processor) does not directly support parameters in script files in the style that your question suggests.
If your product-type and version offers the clpplus command, then you can instead try using the Oracle sqlplus style for passing parameters on the command line and referencing those parameters in your script. See the Db2 and Oracle documentation for details .
I want Task Scheduler in Window run DailyJob.bat daily at a certain time, this file having content like this:
#echo off
DB2 CONNECT TO dbName USER usrName USING password
DB2 .........
DB2 ..........
Moreover, Task Scheduler will run this file by cmd.exe automatically, but cmd doesn't understand DB2 command. Please help me, thanks !
You need to call your db2 statements with the db2cmd command (http://www-01.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.admin.cmd.doc/doc/r0002036.html?cp=SSEPGG_10.5.0%2F3-6-2-6-35)
From CMD.exe
db2cmd -i -c db2 list node directory
There are a lot of related questions in the Web about this problem.
I am running a 2008 SQL server. I am using remote backup to backup the server and have two batch files to trigger the backup process. The first batch file contains:
#echo off
CALL "" "C:\Scripts\SQL Maintainence\Nightly Maintenance 2008 SSE.bat"
The second batch file (Nightly Maintenance 2008 SEE) looks like this:
#echo off
osql -S %SERVER% -d msdb /U (username) /P (password) -i "Nightly Maintenance 2008 SSE.sql" -o "Nightly Maintenance 2008 SSE.txt"
For some reason, the first batch file is not calling for the second batch file to run, the script works when manually ran.
I am very new to writing batch files and have done quite a bit of research up to this point. Any help or maybe an article that can help with my issue would be greatly appreciated.
Reposted as answer instead of question...
I think you need to delete the "" immediately after the CALL, like this:
CALL "C:\Scripts\SQL Maintainence\Nightly Maintenance 2008 SSE.bat"
How do I launch multiple sqlcmd windows from a batch file that all point to the same database? For example, when I run the .bat file I want it to spawn N number of windows based on a parameter that I pass into it (ex. 5). Each of these 5 windows should open on my desktop and all connect to the same database. That's what I want to do first. Once I have that working, I then want to have each of those 5 windows to run a distinct .sql script that performs inserts, queries, updates, deletes, calling stored procedures...essentially emulating a production environment to help us in debugging efforts (under a user load). I want to see the output of each .sql commend flying by in the sqlcmd window while it is being executed.
I found:
http://hammerora.sourceforge.net/
which is a GUI tool that is focused on TPC-C load testing, but it is not exactly what I want. I bring it up because it is a similar concept that I want to do only driven by batch files on a smaller scale (ex. 20 concurrent users max).
I created a system like this back in the late 90's for Oracle scalability testing but I've been out of the database business since then and can't remember how to do it and how different it would need to be to support SQL Server. So I know it is possible in Oracle, but just not sure about SQL Server given the command line tool and scripting capabilities.
Does anyone have any information about what it would take to make this work?
Ex. Create a launch3users.bat file that looks like:
sqlcmd -d MichaelTest -run this 1.sql file
Pause
sqlcmd -d MichaelTest -run this 2.sql file
Pause
sqlcmd -d MichaelTest -run this 3.sql file
Pause
where each of those would spawn a sqlcmd window and run the proper .sql script which could do DML operations or called stored procedures.
Thanks,
Michael
You simply add "start" to the beginning of commands.
start sqlcmd -d MichaelTest -i 1.sql
start sqlcmd -d MichaelTest -i 2.sql
start sqlcmd -d MichaelTest -i 3.sql