Subject Re: [firebird-support] Dropp table if exists
Author Helen Borrie
At 07:22 PM 1/03/2005 +0200, you wrote:


>I am converting a sql database to firebird...
>
>I cannot figure out how to check if a object already exists and if it does
>drop it
>
>This is my best best but it does not work:
>
>IF exists (select * from RDB$GENERATORS where RDB$GENERATOR_NAME =
>'GEN_USEDDS_ID1')
>then
>drop'GEN_USEDDS_ID1'

1. RDB$Generators stores generator definitions, not table
definitions. Table names are stored in RDB$Relations.

2. DROP <something> won't work with anything. Consult documentation to get
the valid syntax for SQL.

3. DDL operations can't be done from stored procedures.


>Does anyone know how this should be done?

With extreme caution, from a client application, and with exclusive
access. Query RDB$Relations to test whether the table is present; proceed
to issue a DROP TABLE <table-name> on the basis of the result.

>Also if there is a dependency how do I make sure that the objects are all
>deleted ?

The engine won't let you delete objects that have dependencies. Your
application can intercept exceptions and proceed accordingly. You can
query the table RDB$Dependencies to determine your strategy.

Commit rigorously.

./heLen