Hi

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kumarsanjeev
    New Member
    • Oct 2007
    • 4

    #1

    Hi

    There are a table in database , i want to check table is exists on not. if it is exists fist it will drop then create the table.
    how we can implement it these type of condition in db2. i have write query like that.

    IF EXISTS (SELECT * FROM syscat.tables WHERE tabname='AMBCOL UMN')
    THEN
    Drop table AMBCOLUMN;
    ELSE
    CREATE TABLE "AMBCOLUMN" ( "COLUMNID" INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY ( START WITH +1 INCREMENT BY +1 MINVALUE +1 MAXVALUE +2147483647 NO CYCLE NO CACHE NO ORDER ) , "TABLEID" INTEGER NOT NULL , "COLNAME" VARCHAR(50) NOT NULL , "DATABASENA ME" VARCHAR(255) , "SCHEMANAME " VARCHAR(255) , "TABLENAME" VARCHAR(255) , PRIMARY KEY ( COLUMNID));
    END IF;

    ----------------------------------------------------------------------------------

    The give me error like
    SQL0104N An unexpected token "IF EXISTS (SELECT *" was found following
    "BEGIN-OF-STATEMENT". Expected tokens may include: "<space>".
    SQLSTATE=42601

    plz help me............. ............... .
    Sanjeev.Q3
  • kumarsanjeev
    New Member
    • Oct 2007
    • 4

    #2
    Hi every one if it is possible give me result ............... .

    Comment

    • Peter55
      New Member
      • Oct 2007
      • 9

      #3
      Please clarify where you are using the statement. Which environment/language are you using?

      Comment

      Working...