How to create table if not exist?

Database
Enthusiast

How to create table if not exist?

What is the correct coding to create a volatile table if it does not exist?
4 REPLIES
WAQ
Enthusiast

Re: How to create table if not exist?

create volatile table table_name

(

col1 varchar(1)

....

)

on commit preserve rows;

Highlighted
Enthusiast

Re: How to create table if not exist?

Thanks WAQ,

I guess i worded my question wrong, how can I say to create a vlatile table if it does not exist?  Like i need it to check first if that table is already out there first than create, if not just a insert of my select statement

Enthusiast

Re: How to create table if not exist?

1: Volatile table it is valid in that session only.So if there is a create statment for that table in session then it wuold be created else it would not exist.

2:If it is for permanent table and you are trying BTEQ script ,you can try something as follows

.SET ERRORLEVEL 3807 SEVERITY 0 ;

DEL FROM TAB2 ;

.If errorcode =0 then .goto tab2

CREATE TAB2

(

)

.LABEL TAB2

Insert into tab2

(

.

.

)

;

Enthusiast

Re: How to create table if not exist?

Thanks Jigar, Thats exactly what I was looking for.