Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2004
    Posts
    19

    Unanswered: Command Line SQL

    Hey

    I have a few queries, creates, and drops I want to put in a single sql file. I will then execute this sql file from the db2 command line environment.

    The sql will basically be like the following

    -------------------------
    drop table
    create table
    drop table
    -------------------------

    Also, if possible i would like to make the first drop table into 'drop table if exists'. Is this possible? How Could i do this?

  2. #2
    Join Date
    Sep 2003
    Posts
    85
    How about writing a shell script which would connect to the database, test for existence of the table and if so, drop the table?
    Or, do you care if one issues a DROP TABLE and the table doesn't exist?
    Ruby

  3. #3
    Join Date
    Aug 2004
    Posts
    19
    Im not sure if I care if i drop a table which doesnt exist.. what happens? If an error message is simply generated tehn thats fine.


    The main point of the question was if i can have multiple sql statements inside a single text file. I just want my batch file to run the sql file. Im working in a restricted environment so that has to be the format. One batch file which just runs the one sql file

  4. #4
    Join Date
    Sep 2003
    Posts
    85
    Sure thing. You can have multiple SQL statements in a "batch" file.
    And if there's a DROP TABLE tablename and the table doesn't exist, so the output would be something like:
    db2 drop table x
    DB21034E The command was processed as an SQL statement because it was not a
    valid Command Line Processor command. During SQL processing it returned:
    SQL0204N "schemaname.X" is an undefined name. SQLSTATE=42704

Posting Permissions

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