Subject Re: Automatically remove unused PK's from second table??
Author csswa
Manually or with a trigger.

Manually: a stored proc that tests for unused foreign keys and
deletes as needed. Run the SP as part of normal DB maintenance.

Trigger: trigger on delete for t_persons that does the same as the SP
above. Cost is slower deletes on this table IF the t_cars table is
very large.

Regards,
Andrew Ferguson
-- A cop on the edge.


--- In ib-support@y..., "dbasch" <dbasch@y...> wrote:
> Hi,
> If I have 2 tables and 'per_id_fk' references 'car_id_pk':
>
> --t_persons--
> per_id_pk
> per_ssn
> car_id_fk
>
> --t_cars--
> car_id_pk
> car_car_type
> car_car_color
>
>
> Then I insert some records into the t_persons table and a
> corresponding new car type into the t_cars table. If the car type
> already exists I reference the existing car_id_pk with car_id_fk.
> ie...multiple people can have the same type of car
>
> When I delete a record from the t_persons table the corresponding
> car type record is left behind. Eventually, I will have a lot of
car
> types.
>
> How do I remove the car types that are no longer referenced with a
> foreign key in the t_persons table?
>
> Thanks,
> Derek Basch