Subject | Automatically remove unused PK's from second table?? |
---|---|
Author | dbasch |
Post date | 2002-06-07T01:19:11Z |
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
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