How to execute CREATE TABLE script for many tables


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: How to execute CREATE TABLE script for many tables

Hybrid View

  1. #1
    Chris Guest

    How to execute CREATE TABLE script for many tables



    DB2v7.2 on Win2000Server.

    I have a script that will create all my 86 tables in my new DB. I am using
    Command Center to run the script and have the following issues:

    sample of script:
    CREATE TABLE MyTable1 (Col1 int, Col2 int)

    CREATE TABLE MyTable2 (Col1 int, Col2 int)


    -My actual table script is more complex obviously.

    -If I enter entire script with multiple create table statements it fails
    with errors.
    -Try to add ";" terminating char at end of each Create Table, only creates
    1st table
    -Found that "\" (backslash) is a continuing char, so tried placing \ between
    each create table command, errors.


    How do I execute my script? Is command center more for executing 1 sql statement
    at a time? On the interactive tab I can execute a create table command, however
    command fails on the "script" tab - bunch of <join> errors received, like
    it's looking for sql dml statements not ddl? however a drop table ddl works
    on "script" tab...??

    Should I be using a different tool? I tried Script Center however had trouble
    opening my script, or I didn't have a valid "connect to" statement in the
    script. I used the same connect to statement as with Command Center however
    no luck.

    Thanks in advance.

    Chris


  2. #2
    Jose Venancio Guest

    Re: How to execute CREATE TABLE script for many tables


    "Chris" <chris@nospam.com> wrote:
    >
    >
    >DB2v7.2 on Win2000Server.
    >
    >I have a script that will create all my 86 tables in my new DB. I am using
    >Command Center to run the script and have the following issues:
    >
    >sample of script:
    >CREATE TABLE MyTable1 (Col1 int, Col2 int)
    >
    >CREATE TABLE MyTable2 (Col1 int, Col2 int)
    >
    >
    >-My actual table script is more complex obviously.
    >
    >-If I enter entire script with multiple create table statements it fails
    >with errors.
    >-Try to add ";" terminating char at end of each Create Table, only creates
    >1st table
    >-Found that "\" (backslash) is a continuing char, so tried placing \ between
    >each create table command, errors.
    >
    >
    >How do I execute my script? Is command center more for executing 1 sql statement
    >at a time? On the interactive tab I can execute a create table command,

    however
    >command fails on the "script" tab - bunch of <join> errors received, like
    >it's looking for sql dml statements not ddl? however a drop table ddl works
    >on "script" tab...??
    >
    >Should I be using a different tool? I tried Script Center however had trouble
    >opening my script, or I didn't have a valid "connect to" statement in the
    >script. I used the same connect to statement as with Command Center however
    >no luck.
    >
    >Thanks in advance.
    >
    >Chris
    >

    Chris. trys this
    1) connect to your database using CC ( connect to DB user db2admin using
    ....)
    2) this is axample that need work
    --
    --
    -- Project : Test Model
    --
    -- Date Created : Thursday, May 02, 2002 16:41:39
    -- Target DBMS : IBM DB2 UDB 7.x
    --


    --
    -- TABLE: CAD
    --

    CREATE TABLE CAD(
    PETCODIGO VARCHAR(100) NOT NULL,
    PLANOID INTEGER NOT NULL,
    PLANONOME VARCHAR(10) NOT NULL,
    PETNOME VARCHAR(10),
    DATANASC TIME,
    FOTO VARCHAR(18),
    PETTIPO VARCHAR(10) NOT NULL,
    PET_RACA VARCHAR(10),
    PETSEXO VARCHAR(2),
    PETDONO VARCHAR(100),
    PETTELEFONE VARCHAR(10),
    CONSTRAINT Indice15 PRIMARY KEY (PETCODIGO, PLANOID, PLANONOME)
    )
    ;


    --
    -- TABLE: AnimaisOnde
    --

    CREATE TABLE AnimaisOnde(
    CRIADORNOME VARCHAR(80) NOT NULL,
    CRIADOR_END VARCHAR(80),
    CRIADORTELEFONE VARCHAR(10),
    CRIADOREMAIL VARCHAR(10),
    CRIADORURL VARCHAR(10),
    ANITIPO VARCHAR(10) NOT NULL,
    ANIRACA VARCHAR(60),
    ANIMALFOTO VARCHAR(10),
    CRIADORCRIATORIO VARCHAR(50),
    CONSTRAINT Indice1 PRIMARY KEY (CRIADORNOME)
    )
    ;


    --
    -- TABLE: APLICACOES
    --

    CREATE TABLE APLICACOES(
    CODIGOAPLIC INTEGER GENERATED ALWAYS AS IDENTITY (START WITH
    0, INCREMENT BY 1, NO CACHE),
    DESCRI VARCHAR(80),
    CUSTO DECIMAL(8, 2),
    CONSTRAINT Indice5 PRIMARY KEY (CODIGOAPLIC)
    )
    ;


    --
    -- TABLE: CadUsuario
    --

    CREATE TABLE CadUsuario(
    Usuario_nome VARCHAR(10) NOT NULL,
    Usuario_Emp VARCHAR(80) NOT NULL,
    Usuario_Nome_fant VARCHAR(80),
    Usuario_end VARCHAR(80),
    Usuario_senha CHAR(10),
    Usuario_email CHAR(20),
    CONSTRAINT PK16 PRIMARY KEY (Usuario_nome)
    )
    ;



  3. #3
    Greg Nash Guest

    Re: How to execute CREATE TABLE script for many tables

    Hi,

    In the Command Center, there's a setting for the "statement termination
    character". It's probably set to ; which should work ok for you.
    Note that in the CC you have to be in the script page, not the
    interactive page, to run multiple commands.

    If you want to use a command prompt to run multi-line commands, you can
    open a DB2 Command Window and type
    db2 -tdX
    where X is the character you want to use as a separator e.g.
    db2 -td@
    or
    db2 -td;

    Certain DB2 utilities default to using @ as a statement terminator for
    scripts so you can use ; to terminate inside a trigger or sql procedure.

    --greg
    Jose Venancio wrote:
    > "Chris" <chris@nospam.com> wrote:
    >
    >>
    >>DB2v7.2 on Win2000Server.
    >>
    >>I have a script that will create all my 86 tables in my new DB. I am using
    >>Command Center to run the script and have the following issues:
    >>
    >>sample of script:
    >>CREATE TABLE MyTable1 (Col1 int, Col2 int)
    >>
    >>CREATE TABLE MyTable2 (Col1 int, Col2 int)
    >>
    >>
    >>-My actual table script is more complex obviously.
    >>
    >>-If I enter entire script with multiple create table statements it fails
    >>with errors.
    >>-Try to add ";" terminating char at end of each Create Table, only creates
    >>1st table
    >>-Found that "\" (backslash) is a continuing char, so tried placing \ between
    >>each create table command, errors.
    >>
    >>
    >>How do I execute my script? Is command center more for executing 1 sql statement
    >>at a time? On the interactive tab I can execute a create table command,

    >
    > however
    >
    >>command fails on the "script" tab - bunch of <join> errors received, like
    >>it's looking for sql dml statements not ddl? however a drop table ddl works
    >>on "script" tab...??
    >>
    >>Should I be using a different tool? I tried Script Center however had trouble
    >>opening my script, or I didn't have a valid "connect to" statement in the
    >>script. I used the same connect to statement as with Command Center however
    >>no luck.
    >>
    >>Thanks in advance.
    >>
    >>Chris
    >>

    >
    > Chris. trys this
    > 1) connect to your database using CC ( connect to DB user db2admin using
    > ...)
    > 2) this is axample that need work
    > --
    > --
    > -- Project : Test Model
    > --
    > -- Date Created : Thursday, May 02, 2002 16:41:39
    > -- Target DBMS : IBM DB2 UDB 7.x
    > --
    >
    >



  4. #4
    chris Guest

    Re: How to execute CREATE TABLE script for many tables



    Thanks for the help Greg. Also thanks for the help on the
    "User Rights" response.

    Chris


    Greg Nash <GregNashdb2@bigpond.com> wrote:
    >Hi,
    >
    >In the Command Center, there's a setting for the "statement termination


    >character". It's probably set to ; which should work ok for you.
    >Note that in the CC you have to be in the script page, not the
    >interactive page, to run multiple commands.
    >
    >If you want to use a command prompt to run multi-line commands, you can


    >open a DB2 Command Window and type
    > db2 -tdX
    >where X is the character you want to use as a separator e.g.
    > db2 -td@
    >or
    > db2 -td;
    >
    >Certain DB2 utilities default to using @ as a statement terminator for
    >scripts so you can use ; to terminate inside a trigger or sql procedure.
    >
    >--greg
    >Jose Venancio wrote:
    >> "Chris" <chris@nospam.com> wrote:
    >>
    >>>
    >>>DB2v7.2 on Win2000Server.
    >>>
    >>>I have a script that will create all my 86 tables in my new DB. I am using
    >>>Command Center to run the script and have the following issues:
    >>>
    >>>sample of script:
    >>>CREATE TABLE MyTable1 (Col1 int, Col2 int)
    >>>
    >>>CREATE TABLE MyTable2 (Col1 int, Col2 int)
    >>>
    >>>
    >>>-My actual table script is more complex obviously.
    >>>
    >>>-If I enter entire script with multiple create table statements it fails
    >>>with errors.
    >>>-Try to add ";" terminating char at end of each Create Table, only creates
    >>>1st table
    >>>-Found that "\" (backslash) is a continuing char, so tried placing \ between
    >>>each create table command, errors.
    >>>
    >>>
    >>>How do I execute my script? Is command center more for executing 1 sql

    statement
    >>>at a time? On the interactive tab I can execute a create table command,

    >>
    >> however
    >>
    >>>command fails on the "script" tab - bunch of <join> errors received, like
    >>>it's looking for sql dml statements not ddl? however a drop table ddl

    works
    >>>on "script" tab...??
    >>>
    >>>Should I be using a different tool? I tried Script Center however had

    trouble
    >>>opening my script, or I didn't have a valid "connect to" statement in

    the
    >>>script. I used the same connect to statement as with Command Center however
    >>>no luck.
    >>>
    >>>Thanks in advance.
    >>>
    >>>Chris
    >>>

    >>
    >> Chris. trys this
    >> 1) connect to your database using CC ( connect to DB user db2admin using
    >> ...)
    >> 2) this is axample that need work
    >> --
    >> --
    >> -- Project : Test Model
    >> --
    >> -- Date Created : Thursday, May 02, 2002 16:41:39
    >> -- Target DBMS : IBM DB2 UDB 7.x
    >> --
    >>
    >>

    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center