Subject How to detect existing table/procedure/trigger an drop it in isql
Author Björn Latte
I'm somewhat stuck on detecting a tables existence and subsequently dropping it before recreating it or simply creating it if the script is run for the first time it. The whole operation is intended to be done by a script run to isql.

The last thing I came up with is:

SET TERM ^ ;

CREATE PROCEDURE TEMP_DROP_TABLE
AS
declare relid Integer;
BEGIN
SELECT RDB$RELATION_ID FROM RDB$RELATIONS WHERE Name = 'TEST_TAB' into :relid;
IF (relid is not NULL) THEN
BEGIN
DROP TABLE TEST_TAB;
END;
END
^
SET TERM ; ^

EXECUTE PROCEDURE TEMP_DROP_TABLE;

COMMIT WORK;

DROP PROCEDURE TEMP_DROP_TABLE;

COMMIT WORK;

CREATE TABLE TEST_TAB
(
TEST_ID INTEGER NOT NULL,
)
;

COMMIT WORK;


The DROP statement inside the procedure will throw an SQL error on running the script as it is obviously not allowed inside the begin/end block.
The same is needed for Stored Procedures and Trigger as this whole business is aimed at creating a database service release tool for databases deployed at customer sites.

Is there a way to do something like that with fb's isql scripting at all? Doing something like that on MS SQL Server using "if exists (select ...)then drop ..." via MS isql was no trouble at all.

Best regards
Bjoern