Board index » delphi » foreign key: unsuccessfull metadata update

foreign key: unsuccessfull metadata update

Hi there!
I've got quite an interesting problem (as usual :). I have a database with
several master-detail pairs, for which I want to create foreign keys like
that:
alter table table1 add constraint constrname foreign key (field1) references
table2 (field2)
(note that master and detail fields are named differently)
So, all goes well, but only for the first two tables! When I try to do the
same with the others, I get an "sqlcode=607 (STORE RDB$RELATION_CONSTRAINTS
failed)". I've checked everything concerning referential integrity, and I'm
quite sure of that. Even more: I've got 2 copies of the same database, and
with the first copy I've succeeded in creating keys only for tables A and B,
with the second - for tables C and B; it seems like that what matters is
order of creation, not some substantial causes.
Anybody knows what's wrong?
 

Re:foreign key: unsuccessfull metadata update


Quote
"NicLis" <m...@lisov.domino.dp.ua> wrote in message <news:9pvgjd$2sc7$1@pandora.alkar.net>...
>..I get an "sqlcode=607 (STORE RDB$RELATION_CONSTRAINTSfailed)".

That a piece of code that worked

              sz1:='SOME_NAME'
              sz:='ADD CONSTRAINT '+sz1;
              self.Query.SQL.Add(sz);
              sz:='FOREIGN KEY('+indnam+')';
              self.Query.SQL.Add(sz);
              sz:='REFERENCES '+tabnm+'('+indnm+')';
              self.Query.SQL.Add(sz);
              SetWork;
              try
               self.Query.ExecSQL;
               CommitWork;
              except
               RollBackWork;
              end;

procedure SetWork;
begin
 Database.StartTransaction;
end;

procedure RollBackWork;
begin
 if Database.InTransaction then
  Database.Rollback;
end

Other Threads