Connecting Tech Pros Worldwide Help | Site Map

Hi

Newbie
 
Join Date: Oct 2007
Posts: 4
#1: Oct 31 '07
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='AMBCOLUMN')
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 , "DATABASENAME" 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
Newbie
 
Join Date: Oct 2007
Posts: 4
#2: Oct 31 '07

re: Hi


Hi every one if it is possible give me result ................
Newbie
 
Join Date: Oct 2007
Posts: 9
#3: Nov 2 '07

re: Hi


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


Similar DB2 Database bytes