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

this is not a bug, it's supposed to work this way

 

the batch (everything before the "go") is compiled before being executed

if the table already exists, the create table statement will fail.

 

it works with exec immediate, because the compilation of the executed statement is delayed till actual execution time. that part is never reached if the table exists.

 

few approaches possible:

1. if you always want to drop & recreate all tables, then always perform a drop table before the create table (this means all data is lost every time you rerun the script)

 

2. use exec immediate, like the way you do now

 

3. if you have 1 script per table, you could select syb_quit() if the table already exists

e.g.

IF EXISTS (SELECT * FROM sysobjects WHERE name="TestExec")

     select syb_quit()

go

 

create table....

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>