Subject Re: [firebird-support] Restore without constraints
Author Rik van Kekem
Köditz, Martin Martin.Koeditz@... [firebird-support] wrote:
> is it possible to restore a database without constraints? Or is there
> another way to do this? I just want do delete each primary key in the db.

Is this on a healthy DB? I'm not sure if -I disables the constraints in
that case. You can use -I -N. (-N for disabling the constraints). After
that you can remove the primary records.
See http://www.firebirdsql.org/manual/gbak-cmdline.html

But then what???? If you activate the indexes and constraints again you
face the same problem (you can't because of the sub-records).

If the DB was build correctly there should have been a ON DELETE CASCADE
on the constraint. Maybe you still can change the constraints with a ON
DELETE CASCADE. Removing the records from the primary table will delete
all sub-records too.


Either way... with this you can activate all indexes and constraints
again (but only if you also deleted the sub-records with the foreign keys):

EXECUTE BLOCK AS
DECLARE VARIABLE stmt VARCHAR(1000);
BEGIN
for select 'ALTER INDEX '||rdb$index_name ||' ACTIVE;'
from rdb$indices
where (rdb$system_flag is null or rdb$system_flag = 0)
order by rdb$foreign_key nulls first
into :stmt
do EXECUTE STATEMENT :stmt;
END