Subject Re: [firebird-support] How to know if a field already exists on a table
Author Pavel Menshchikov
Hello Carol,

CM> (First) How to know if a field already exists on a table?
CM> Is this possible?
Yes.

CM> Select AFIELD
CM> From SOMEWHERE_ON_THE_DATABASE

CM> If result is not null, the field exists?

CM> (Second) **If** the question above is valid,
CM> can I implement a stored procedure to check existence of fields on tables?

create or alter MY_STORED_PROCEDURE
(
AField char(31), /* must be upper-cased, also see a remark below */
ATable char(31) /* must be upper-cased, also see a remark below */
)
returns
(
AResult smallint /* 0/1 */
)
as
begin
if (exists(select 1 from rdb$relation_fields
where rdb$relation_name=:ATable /* OR you may upper-case ATable here */
and rdb$relation_field=:AField /* OR you may upper-case AField here */
and rdb$system_flag=0)) then
AResult=1;
else
AResult=0;
end


HTH
--
Best regards,
Pavel Menshchikov
http://www.ls-software.com