Subject | Re: [firebird-support] Temporary disable FK constraint |
---|---|
Author | Scott Morgan |
Post date | 2015-11-06T16:48:52Z |
On 06/11/15 16:15, Rik van Kekem rik@... [firebird-support] wrote:
SQL> ALTER INDEX FK_FOO INACTIVE;
unsuccessful metadata update
-MODIFY RDB$INDICES failed
-action cancelled by trigger (2) to preserve data integrity
-Cannot deactivate index used by an integrity constraint
Scott
> Scott Morgan blumf@... [firebird-support] wrote:You can't inactivate a FK constraint:
>> In a FB2.5 system is there a way to temporarily disable foreign key
>> constraints? i.e. something like 'ALTER INDEX ... INACTIVE'
> Well, here is the way to activate indexes and foreign keys:
> How to activate all indexes? http://www.firebirdfaq.org/faq274/
>
> So doing the reverse should work too:
> SET TERM !! ;
> EXECUTE BLOCK AS
> DECLARE VARIABLE stmt VARCHAR(1000);
> BEGIN
> for select 'ALTER INDEX '||rdb$index_name ||' INACTIVE;'
> from rdb$indices
> where (rdb$system_flag is null or rdb$system_flag = 0)
> order by rdb$foreign_key nulls last
> into :stmt
> do EXECUTE STATEMENT :stmt;
> END!!
> SET TERM ; !!
>
> (not tested)
SQL> ALTER INDEX FK_FOO INACTIVE;
unsuccessful metadata update
-MODIFY RDB$INDICES failed
-action cancelled by trigger (2) to preserve data integrity
-Cannot deactivate index used by an integrity constraint
Scott