FIREBIRD Questions and Answers

How to drop all foreign keys in database?

Deleting all foreign keys can be done by querying the system tables and droping them one by one. If you use Firebird 2 or higher, it can be done with a single SQL statement:
set term!!;
EXECUTE BLOCK RETURNS (stmt VARCHAR(1 000)) AS
BEGIN
FOR
select ‘alter table ‘||r.rdb$relation_name ||’ drop constraint’|| ‘ r. rdb$constraint_name||’;’ from rdb$relation _constraints r
where (r. rdb$constraint_type=’FORETGN KEY’)
into :stmt
DO begin suspend; execute statement :stmt; end
END!!
set term; !!
If you use Firebird i .x, you can run the following query to get statements to execute and then copy/paste the result and execute:
select ‘ALTER TABLE’ ||r. rdb$relat ion_name
||’DROP CONSTRAINT’|| r. rdb$constraint_name||’:’
from rdb$relation_constraints r
where (r.rdb$constraint_type=’FORETGN KEY’)