I have a script in a file (mysqlscript.sql) that is basically a bunch of inserts/updates/deletes separated by GO statements
insert into ....
GO
update .....
GO
How do I run this script?
You can try to use $system.SQL.ImportDir()
And of course, you can read your file and execute each sql-query in your programm.
The tool Caché Monitor use GO as statement separator and connects to InterSystems Caché. With this tool you can execute your script.
Related
I am in the need of switching from Aginity Workbench to something else for a redshift database [read only user], i was suggested DBeaver
i have searched google in many ways but cannot find a way to Export a result set to CSV without manually running the script then exporting.
With Aginity, i could run exports from command line [Opens and Copies a SQL File resultset directly to CSV], and batch then up [around 150 or so extracts each morning, so manually running would take too long]
Does DBeaver have similar functionality? even if its just a copy to csv sql script i can run from inside DBeaver as a select query [which i do currently with postgres]
Yes, It does and follow below.
Right click on table(Redshift or Azure)
You can select the format(.csv or any listed below format) of output file as shown in below
http://pgtap.org/integration.html#perl mentions how to run the tests, but I cannot find an example of a Perl test case.
Do I have to get a DBI connection manually, run my commands on it, and check the results?
Does it even make sense to use Perl vs SQL code?
Am I missing something?
pgTap is for parsing SQL output - output from running an SQL script via psql from the command line. An SQL script that contains pgTap SQL calls mixed in with the SQL statements that you wish to test.
As such, DBI doesn't enter into it.
I am facing a problem in DB2. In my Oracle environment it was very easy for me to include multiple scripts in one master script, which were executed sequentially. e.g.:
Master.sql:
connect ....
#script1.sql
#script2.sql
Now I have to build up same logic in DB2 LUW. Is there a simple way to include multiple scripts in one master script? I would like to have one single db2 call from shell, which executes the master script and within all subscripts.
Regards
Jan
There is notrhing to stop you from creating a single file with multiple sql batches. In the Windows world, it would look like this:
Note: First you initialize the db2 command prompt.
db2cmd -c -w -i %1.bat
With as many of these as you want in the .bat file:
db2 -txf c:\Example\db2html.sql
In Linux, the db2clp is included in the shell once you load the db2profile ('. /home/db2inst1/sqllib/db2profile). In windows, you need to call db2cmd in order to use db2clp.
With a interactive db2clp, you cannot call db2 scripts via #scriptX, however, you can call them from the shell like
db2 -tvf script
However, if you use the CLP*Plus you can do almost everything you do in SQL*Plus. For more information: https://www.ibm.com/developerworks/community/blogs/IMSupport/entry/tech_tip_db2_s_new_clp_plus_utility?lang=en
I have created a stored procedure which takes 3 arguments
databaseName
backupType
backupLocation
if i run this stored procedure its creating the backup.
I want to know hw to write a batch file for this and schedule a job to run at specified time.
I am using sqlserver2008.
Have a look at this article:
sqlcmd utility
You can use the sqlcmd utility in a batch file to execute your procedure.
you can Refer this microsoft link:
This is a microsift link with stored procedure and batch file examples
http://support.microsoft.com/kb/2019698
I have a bunch of SQL scripts (with shell script wrappers) to unload data like so
EXPORT TO /tmp/out.csv OF DEL MODIFIED BY NOCHARDEL COLDEL, DATESISO
MESSAGES /tmp/out.msg SELECT WIDGETID
...
I want to add an error handler to the script the way Oracle does it:
WHENEVER SQLERROR EXIT FAILURE;
SPOOL /tmp/out.csv;
SELECT WIDGETID...
SPOOL OFF;
According to DB2's documentation, this can be done in stored procedures, C, Perl, REXX, and nothing else...
How can this be done in SQL scripts?
I am running DB2/LINUXX8664 9.7.2.
you could use the DB2 command line command processor and get its return code. http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/topic/com.ibm.db2.luw.admin.cmd.doc/doc/r0010411.html
or you could use the SYSPROC.ADMIN_CMD procedure and use its return codes. http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/topic/com.ibm.db2.luw.sql.rtn.doc/doc/r0023573.html
you could put the stored proc calls in a script file and run something like db2 -tvf runexport.txt or put the db2 commands in a linux script file and use linux scripting foo to handle the db2 return codes.