> CREATE TABLE table (ID text UNIQUE, Name text, Surname text, SecDbKey text)
> INSERT INTO table VALUES ('001', 'John', 'Smith', 'A0B1C2D3')
> INSERT OR REPLACE INTO table VALUES ('001', 'Jane', 'Parker', 'E4F51234')

I'm not sure exactly what relationship you're trying to maintain
between this table and the other one, but assuming that SecDbKey
is a foreign key that references table2 and that you have no
duplicate foreign keys (SecDbKey should probably be declared
unique if that's the case), then you can execute

   delete from table2 where table2.DbKey not in
      (select SecDbKey from table)

after you do your <insert or replace>, or after you do several
of them.  You can put it in a trigger if you don't want to do
it explicitly.

BTW, you might want to review your db design.  Usually you
delete foreign keys when the referenced primary key disappears;
you seem to be doing the opposite.

Regards

Reply via email to