Quantcast
Channel: SCN: Message List - SAP Adaptive Server Enterprise (SAP ASE) for Custom Applications
Viewing all articles
Browse latest Browse all 3587

Re: Create Table Statement Error With If Exists Clause

$
0
0

Two alternatives:

1) put the DROP TABLE and CREATE TABLE in separate batches by

putting a "go" before the CREATE TABLE:

use tempdb

go

IF OBJECT_ID('t1') IS NOT NULL

BEGIN

DROP table t1

IF OBJECT_ID('t1') IS NOT NULL

PRINT '<<< FAILED DROPPING table tempdb..t1 >>>'

ELSE

PRINT '<<< DROPPED table tempdb..t1 >>>'

END

go

CREATE TABLE t1

(

c1 varchar(15) NULL

)

go

2) put the CREATE TABLE within the context of an EXECUTE IMMEDIATE

statement, so that the CREATE

isn't evaluated until the EXECUTE is executed, at which point the

older table with the same name will not exist:

use tempdb

go

IF OBJECT_ID('t1') IS NOT NULL

BEGIN

DROP table t1

IF OBJECT_ID('t1') IS NOT NULL

PRINT '<<< FAILED DROPPING table tempdb..t1 >>>'

ELSE

PRINT '<<< DROPPED table tempdb..t1 >>>'

END

execute

("

  CREATE TABLE t1

  (

   c1 varchar(15) NULL

  )

")

go


Viewing all articles
Browse latest Browse all 3587

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>