dbTalk Databases Forums  

Check if a column exists

sybase.public.sqlanywhere.general sybase.public.sqlanywhere.general


Discuss Check if a column exists in the sybase.public.sqlanywhere.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
blackbird
 
Posts: n/a

Default Check if a column exists - 02-21-2010 , 08:48 PM






Hopefully a simple one, but I can't find anything obvious in the docs.

I want to add a column to my database only if it doesn't exist, as my
versioning scheme has gone a bit awry.

Can I put the statement in some sort of SQL try-catch, or is there an
easy way to check before adding?

Thanks

Reply With Quote
  #2  
Old   
tduemesnil
 
Posts: n/a

Default Re: Check if a column exists - 02-22-2010 , 01:11 AM






On 22 Feb., 03:48, blackbird <adam.c.k... (AT) gmail (DOT) com> wrote:
Quote:
Hopefully a simple one, but I can't find anything obvious in the docs.

I want to add a column to my database only if it doesn't exist, as my
versioning scheme has gone a bit awry.

Can I put the statement in some sort of SQL try-catch, or is there an
easy way to check before adding?

Thanks
if not exists ( select 1
from sys.syscolumns
where creator = '__OWNER__'
and tname = '__TABLE__'
and cname = '__FIELD__'
) then

end if;
HTH

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.