Subject Re: [firebird-support] Checking if a table exists ...
Author Lucas Franzen
Anand,


akashelkar schrieb:

> How can I check, inside a stored procedure as well as from an
> application, if a specific table or view or procedure or any other
> object exists in the database?

Query the system tables:

Tables:
-------
SystemTable = RDB$RELATIONS
Tablename = RDB$RELATIONS.RDB$RELATION_NAME

Add. Where = RDB$RELATIONS.RDB$SYSTEM_FLAG = '0' AND
RDB$VIEW_BLR IS NULL

Views:
------
SystemTable = RDB$RELATIONS
Tablename = RDB$RELATIONS.RDB$RELATION_NAME

Add. Where = RDB$RELATIONS.RDB$SYSTEM_FLAG = '0' AND
RDB$VIEW_BLR IS NOT NULL


Procedures:
------------
SystemTable = RDB$PROCEDURES
ProcName = RDB$PROCEDURES.RDB$PROCEDURE_NAME

Add. Where = RDB$PROCEDURES.RDB$SYSTEM_FLAG = '0'


But: inside a stored procedure this isn't very helpful since what to do
with the information then?

If the table exists do a select?

This will fail, since if it doesn't exist, the procedure won't compile ;-)

Luc.