Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Posts
    2

    Question Unanswered: how to call several create table statements???

    hi guys,

    i am new to db2.
    How can i call several create table statements in just one script.
    it would be also great to set the schema in that script.
    is there a special tool from db2 availabel or is java an option?
    please help me out here (with examples)!!!!!

    Thanx
    juan

  2. #2
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    Create a file with the SQL statements you want. These can include set schema, create table, or msot other SQL statement. Separate each SQL statement with semi-colon ( ; ).

    Then from your OS command prompt execute the following (assume the above file with your SQL statements is named "sql_input"):

    db2 –tvf sql_input

    See the Command Reference manual for other Command Line Processor options. To download DB2 manuals, see the first thread entitled Useful DB2 Stuff.
    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 2003
    Posts
    78

    Smile example

    use notepad, save with extension sql,this should work:

    example.sql:

    SET CURRENT SCHEMA MYSCHEMA
    CREATE TABLE "MYSCHEMA"."MYTABLE1" (
    "MYVARCHAR1" VARCHAR(255) NOT NULL,
    "MYINTEGER1" INTEGER NOT NULL,
    "MYCHAR1" CHAR(20) NOT NULL
    );
    CREATE TABLE "MYSCHEMA"."MYTABLE2" (
    "MYVARCHAR2" VARCHAR(255) NOT NULL,
    "MYINTEGER2" INTEGER NOT NULL,
    "MYCHAR2" CHAR(20) NOT NULL
    );


    i suggest u put some blank lines at the end of the file.

    then using Command line processor, do the following:


    db2 => quit
    DB20000I The QUIT command completed successfully.

    C:\PROGRA~1\SQLLIB\BIN>
    C:\PROGRA~1\SQLLIB\BIN>db2 connect to mydb
    ....

    C:\PROGRA~1\SQLLIB\BIN>db2 -tvf example.sql


    note that after quit, you should change your directory to where you have saved the file with "cd" command

Posting Permissions

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