Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread CREATE TABLE IF NOT EXISTS
Thu, Jun 9 2011 10:12 PMPermanent Link

IQA

I'm just wondering if EDB SQL has the equivelant of: CREATE TABLE IF NOT EXISTS

I know I can query the information database and check for table names...

But the reason I ask is, I am using a EDBScript component to load an SQL file which creates 50 or so tables with "default data" when my program is executed, so that initially the tables are created if it's the first run and also any tables not created will be created, but I don't want to hard code checking of 50 tables which could also change to become 55 tables in future releases.

I just want to add something like CREATE TABLE IF NOT EXISTS to my .SQL file so that if the table doesn't exist it will be created.

Thanks
Fri, Jun 10 2011 2:54 AMPermanent Link

David Cornelius

Cornelius Concepts

Avatar

No, but you can write a function to do it.  Or copy one I did:

http://www.elevatesoft.com/forums?action=view&category=edb&id=edb_extensions&msg=38&page=1

Actually, that function can now be shortened to eliminate cursors with new
extensions in EDB:

http://www.elevatesoft.com/manual?action=viewtopic&id=edb2sql&topic=EXECUTE_IMMEDIATE


Hope that helps!

David Cornelius
Cornelius Concepts
Fri, Jun 10 2011 4:04 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Philip

>I'm just wondering if EDB SQL has the equivelant of: CREATE TABLE IF NOT EXISTS

To my eternal sadness that syntax didn't make it into ElevateDB. However, since you're using a script the easiest way is either use David's approach or simply wrap the create statement in BEGIN EXCEPTION END.

My preferred approach is testing the configuration but I just don't like exceptions, even nicely handled ones.

Roy Lambert [Team Elevate]
Fri, Jun 10 2011 7:15 AMPermanent Link

IQA

Thanks David (nifty function) works well and thanks Roy, your right I don't like relying on exceptions either.
Image