How do I create a batch file to run the multiple DB2 SQL queries?

Ananth F July 23, 2013
Pinterest Stumbleupon Whatsapp

I am executing multiple DB2 SQL commands frequently. It is taking lot of time to do this manually so I want to automate this using a batch file.

How can I do this?

  1. Hovsep A
    July 24, 2013 at 8:00 pm

    perhaps to merge all the files into a single file, COPY a.sql + b.sql + c.sql d.sql
    , creating a single .sql file.

    Use sqlcmd with Scripting Variables
    http://msdn.microsoft.com/en-us/library/ms188714.aspx

    Using SQLCMD to loop through list of servers
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/e7a750d8-b41e-4b48-8147-e85f6b77bb29/using-sqlcmd-to-loop-through-list-of-servers

    Centralized Data Collecting, Using SSIS
    http://jahaines.blogspot.fr/2009/07/centralized-data-collecting-using-ssis.html

    SQL Server – Executing Multiple Script Files Using SQLCMD
    http://www.toadworld.com/platforms/sql-server/b/weblog/archive/2013/03/25/sql-server-executing-multiple-script-files-using-sqlcmd.aspx

  2. Bruce E
    July 24, 2013 at 12:20 am

    Instead of trying to set up a batch file to handle the issue, is it possible write a stored prcedure instead? In most cases a stored procedure is far more efficient, some databases will allow you to pin them in memory for faster access as well as optimixing its execution path. Of course, some of this may depend on exactly what you want to accomplish the the SQL commands you are issuing in the first place.

    Some RDBMS will allow you to have global stored procedures that can be executed against the system talbes and with some restrictions (or a lot of work) on any other database on the system. Others will only allow stored procedures that can run on a particular database.

    Once you have a stored procedure set up, you simply use a simple call to the database to execute the stored procedure.

    • Ananth F
      July 24, 2013 at 11:33 am

      Hi Bruce E,

      Thank you for your comments.
      I will try your idea.