Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2007

    Unanswered: executing multiple .sql files

    Hi everyone,

    I am still new to both Shell script and db2. Currently I have a lot of .sql files to be executed. Therefore, I would like to ask how am I going to execute the files by just a few lines of command in Shell script? Thanks.

    Teck Guan.

  2. #2
    Join Date
    May 2003
    Create a shell script as follows (I will call it

    db2 -tvf file1.sql > file1.out
    db2 -tvf file2.sql > file2.out
    db2 -tvf file3.sql > file3.out
    db2 -tvf file4.sql > file4.out
    db2 -tvf file5.sql > file5.out

    Make sure each of the above files has a "connect to db-name;" as the first statement. Each SQL statement will be terminated by a ";".

    Then issue the following command to give execute authority on the script:
    chmod 775

    The execute the script (this assumes you are on the correct path):
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

  3. #3
    Join Date
    Dec 2007
    Thanks. However, if I have 500 .sql files, I will have to type 500 lines. Therefore, I would like to ask is there any ways to execute the .sql files in easier way?

    Teck Guan.

  4. #4
    Join Date
    Jan 2007
    Jena, Germany
    You could use a simple loop in the shell script:
    db2 "connect to <dbname>"
    for f in *.sql; do
        db2 -f $f > $f.output
    Note that Marcus used some additional options for the db2 CLP - namely, -t and -v. You may want to read up on those options (and others) and determine which ones you need.
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts