views:

599

answers:

2

I want to disable all Foreign key constraints and re-enable them after, is there some way to do that?

I know that SQLServer allows that, but what about Firebird?

+1  A: 

AFAICT foreign keys can't be disabled in Firebird up to 2.1.
You'd have to drop and recreate them.
There's a similar thread on Devshed.

Douglas Tosi
+1. With a tool that shows the system tables one can see that there is no field in RDB$RELATION_CONSTRAINTS that would allow to disable foreign key constraints. Indexes OTOH can be made inactive, and RDB$INDICES has a field RDB$INDEX_INACTIVE.
mghie
Yes, but indexes that support constraints cannot me deactivated. Trying to do so results in an error.
Douglas Tosi
A: 

I guess the only way is to drop and later re-create them. Since constraints are not data, you really do not lose any information from the database, so it is a harmless operation (provided that you keep the script to recreate them later).

Version of FlameRobin in SVN repository has an option to generate those DROP and CREATE scripts automatically for chosen table column dependencies. Last official release has the same option for entire tables, so that might help you. There is no option to do it for the whole database, though. Maybe some other admin. tool has that feature.

Milan Babuškov