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

Ananth F July 23, 2013

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

    Using SQLCMD to loop through list of servers

    Centralized Data Collecting, Using SSIS

    SQL Server – Executing Multiple Script Files Using SQLCMD

  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.