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 .
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
Want a syntax where I can give my DB2 details like server name,user name,password and sql file which want to execute using batch file.
I found syntax like sqlplus,sqlcmd for oracle and sql server respectively but no luck for 'DB2'.
Pls help me in it.
Note that this is about DB2 on the IBM i platform (see comments).
For Windows, from a command prompt, type db2cmd, then from there run e.g. db2 connect to YOUR_DATABASE user YOUR_USER_ID then e.g. db2 -tf filename.sql
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.cmd.doc/doc/r0002036.html
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.cmd.doc/doc/r0010410.html
IBM i Access Client Solutions (which I assume you have available to you, this part of its functionality being free of charge) has a command line option for this, e.g.
java -jar acsbundle.jar /SYSTEM=MYAS400 /PLUGIN=rss /file=\mysqlscript.sql /autorun=1
See ftp://ftp.software.ibm.com/as400/products/clientaccess/solutions/GettingStarted_en.html for more information (specifically section 9.1.31).
I think, this might help somebody in future, who is looking for solution,Just make sure you have Db2 Client installed & add following snippet in your batch file.
SET DB2CLP=DB20FADE
runas /noprofile /user:db2admin "db2cmd -c db2 create database MyDatabase && db2 connect to MyDatabase && db2 -tvmf db2_create_tables.sql"
I too faced many issues but after some research i came up with this solution, i hope it will help you/someone.
Well, I guess you didn't really search.
Db2 has several command line interfaces that can be and are used for batch processing. Clpplus even offers Oracle-like syntax support and compatibility. There is even a tool named db2batch that allows to process statements with lots of options.
I am struggling to create a database using SQLite3 using Windows 7.
SLite3 is currently installed:
C:\Program Files (x86)\Development\
and has sqlite3.def, sqlite3.dll and a sqlite3 (.exe) file.
I have also updated the environment variable of Path to:
C:\Program Files (x86)\Development\
When I double click:
sqlite3.exe
It opens up the command prompt with the address at the top as:
C:\Program Files (x86)\Development\sqlite3.exe
It opens up and is:
"Connected to a transient in-memory database."
(transient in-memory database) is in red text
Looking around this means that it saves to memory and not hard disk but if you specify:
.save testDB
Then all should be good, but not for me. I have tried:
sqlite3 testDB.db
.save testDB
create table tbl1(one varchar(10), two smallint);
But I get the error:
Error: near "sqlite3" syntax error
Any ideas what I'm doing wrong? I have SQLite manager installed too but I assume I can't use that until a database is saved to disk?
Thanks.
Would changing my Path variable to:
C: \Program Files (x86)\Development\
Make any difference i.e. a space between : and the \?
I ran into the same problem and found help here on the official website. Essentially, you can double-click on the sqlite3.exe file. Then use the .open command to get a persistent database. To create your testDB.db database, you can do as follows:
SQLite version 3.8.8.3 2015-02-25 13:29:11
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .open c:/sqlite/testDB.db
sqlite>
This should create testDB.db in c:/sqlite or some other folder you specify.
You do not need sqlite3.def or sqlite3.dll.
There are two ways if starting the sqlite3 command-line shell, either by double-clicking on the .exe, or by typing sqlite3 and any parameters in the Command Prompt.
Do not try to start sqlite3 from inside itself.
SQLite Manager is able to create a new database.
Using a wrong path would not work.
Reach the path where you want to start with SQLite through command prompt, for e.g. c:\sqlite>. Now when I use ls command I get c:\sqlite>ls
sqlite3.exe
Now to create database type c:\sqlite>sqlite3 database.db It will create a database for you.
Add sqlite3.exe in a folder, for example: C:\sqlite3\sqlite3.exe
Now go to the path where the sqlite3.exe is and run it.
Per the '.help' instructions, type '.save filename'. When reopening, type '.open filename'. This worked for me.
OrientDB is using console command create DB by the way run console.bat file on "..\orientdb\bin\". However i need create a .bat separate file run like this command:
create database remote:localhost/test <root> <password> local graph
And run that .bat file by PHP
Thank for advance !
Based on the old documentation at https://code.google.com/p/orient/wiki/ImportFromRDBMS it seem that it is possible and is similar to what i want to do as well.
console.bat database.sql
where all your sql commands are in database.sql. The link about includes a sample for porting a full database over but don;t see why it should not work for similar scripts as well.
That said i have not tested this yet.
I restored my development database from production, and the stored procedures I need in my development environment doesn't exist in my production database. Is there a command Ii can use to import the developmetn stored procedures back into SQL Server. There are about 88 files, as each procedure is in a different text file.
TIA!
Chris
Oops, you did the painful way of generating scripts. You should have created a single script for all procedures by right clicking on the database in SSMS, choosing Tasks -> Generate Scripts.
However, if you don't want to go through that process again, open up a cmd shell in the folder and remember those old batch file days:
for %f in (*.sql) do sqlcmd -i %f
This should do the trick!
You could add other parameters to sqlcmd if required (i.e. login, password, server name, ...). To see a list of switches just do a sqlcmd -h.
For SQL 2K & 2K5, you want this tool.
I asked a similar question awhile ago and got this advice from Mike L (give him votes here).
Right click on the database from where you want to transfer the data
Select Data Transfer
Select Tables or Store Procedure (what you want to transfer)
Select the location where you want to transfer the data (either on server or localhost or any file)
Right click on the development database Hit Generate SQL Scripts and then only select stored precedures. If you need need additional filtering you can even select the stored procedures you dont want.
Then just run that query on development.
I don't know if there's a command line way to do it, but if you have them all in text files, it shouldn't be difficult at all to write a quick down and dirty app that just loops through all the files, and runs the create statements on your production server using whatever language you choose.
If like me you have to deal with a bunch of sql files in a hierarchy of folders, this one liner will combine them into a single file called out.sql which you can easily execute in SQL Management studio. It will only include files that END in .sql, and ignore files such as *.sqlsettings.
Run it from the root folder of the hierarchy of .sql files. Be sure you have nothing of value in out.sql, as it will be replaced.
del out.sql && for /f %f in ('dir /b /s ^| findstr /E \.sql') do type %f >> out.sql