Subject Re: [ib-support] Check if field exists before adding
Author Paul Vinkenoog
> SELECT COUNT (RDB$FIELD_NAME)
> FROM RDB$RELATION_FIELDS
> WHERE RDB$FIELD_NAME = MYFIELDNAME
>
> If the fieldname is not unique, add
>
> AND RDB$RELATION_NAME = MYTABLENAME
>
>
> This returns 1 if the field exists, 0 if not.
>
> You can also remove COUNT( ) from the SQL. Then you get the field name
> if it's there, NULL if it isn't.

Come to think of it: if you have lots of fields in your db and if you
use Firebird, it might be speedier to change the first line to

SELECT FIRST 1 RDB$FIELD_NAME

so the engine stops searching once the thing is found (EXISTS-like
behaviour).

Greetings,
PV