Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2009
    Posts
    2

    Unanswered: Help with inserting SQL statements into DB2 database from file

    I have a text file containing SQL statements. I wish to run this file in DB2 database to execute the statements. The file contains a series of simple row inserts.

    eg.
    INSERT INTO x (a, b, c, d, e) VALUES ('f', 'g', 'h', 'i', 'j')
    INSERT INTO ....
    etc.

    Can anyone please assist? I aware that there is an 'insert into x from file y' command somewhere.

    Thanks.

  2. #2
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    Put this in a file:
    connect to sample;

    INSERT INTO x (a, b, c, d, e) VALUES ('f', 'g', 'h', 'i', 'j');
    INSERT INTO x (a, b, c, d, e) VALUES ('f', 'g', 'h', 'i', 'j');

    connect reset;

    The from command window:

    db2 -tvf <file-name>
    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
    Sep 2004
    Location
    Belgium
    Posts
    1,126
    Alternatively, have a look at the "import" command.
    --_Peter Vanroose,
    __IBM Certified Database Administrator, DB2 9 for z/OS
    __IBM Certified Application Developer
    __ABIS Training and Consulting
    __http://www.abis.be/

  4. #4
    Join Date
    Jan 2003
    Posts
    1,605
    italia1980,
    if you don't have ";" at the end of each command, you must have each command in its separate row. If so, you can use command:
    db2 -f <file-name>

Posting Permissions

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