I'm having a hard time wrapping my brain around this and hoping someone can help. I know how to grab an ID from a row if I am deleting 1 record so that I can delete the record that goes with it, but I'm not sure how to do it when deleting multiple records.Below is my code for Deleting my multiple records:ALTER PROCEDURE [dbo].[ap_DeletePlans] @Login_ID int, @PlanGuid varchar(36)AS BEGIN DELETE FROM Plans WHERE [Login_ID] = @Login_ID AND [PlanGuid] = @PlanGuid END
My Plans table has a field called SubPlan_ID that points to a table called SubPlans that has an identical field (how they are matched) that is the Primary Key / Identifier. What I need to do is when I delete all records from Plans I need it to delete a record (if it exists) from SubPlans too.Edit: Thought it might be easier to read if I post my columns in both tables that are relevant.Plans-------------Login_ID Plan_ID PlanGuid SubPlan_ID ...More unrelated fields | |SubPlans |------------- |Login_ID SubPlans_ID <----------------