Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A way to check if the temporary table exists or not

Tags:

sybase

sap-ase

I have this following query :

IF NOT EXISTS (SELECT 1
               FROM   sysobjects
               WHERE  id = Object_id('tempdb..TEMP_THETH_DETAILS'))
  EXECUTE (
'CREATE TABLE tempdb..TEMP_THETH_DETAILS( THETH_ID NUMERIC(5) NOT NULL, LANGUAGE VARCHAR(3) DEFAULT ''EN'' NOT NULL)'
)

GO 

The problem is the checking, it seems tempdb doesnt take on consideration if not exist, maybe because the table was create in the tempdb.
So my question is there a way I can check if the temporary table exists or not ?

like image 287
Moudiz Avatar asked Mar 24 '23 11:03

Moudiz


1 Answers

Try this:

IF object_id('tempdb..TEMP_THETH_DETAILS') is null
begin
   EXECUTE 
   (
       'CREATE TABLE tempdb..TEMP_THETH_DETAILS
        ( THETH_ID NUMERIC(5) NOT NULL, 
          LANGUAGE VARCHAR(3) DEFAULT ''EN'' NOT NULL
        )'
    )
end
go
like image 157
Robert Avatar answered Apr 27 '23 09:04

Robert