Subject | Re: [firebird-support] sql to check if a row has been used in related tables? |
---|---|
Author | Lucas Franzen |
Post date | 2007-03-26T15:30:13Z |
wang960 schrieb:
a quick and dirty workaround might be:
if all your fields are defined as foreign keys you can do a delete on
the master record and get the AffectedRows. If the result is bigger than
1 or if an error occurs (if one of the foreign keys is not declared as
on DELETE CASCADE) then you can be quite sure there are dependencies...
Do a rollback afterwards if you don't want to delete the record in that
case.
Luc.
> Hi,Well,
>
> I have a table called Item with keyfield itemno, and there are many
> tables use the itemno as foreign key, is there a generic way to check
> if a certain itemno already exists in one of related tables? Thanks.
>
>
a quick and dirty workaround might be:
if all your fields are defined as foreign keys you can do a delete on
the master record and get the AffectedRows. If the result is bigger than
1 or if an error occurs (if one of the foreign keys is not declared as
on DELETE CASCADE) then you can be quite sure there are dependencies...
Do a rollback afterwards if you don't want to delete the record in that
case.
Luc.