I’m tasked with deleting entries from a parent table which means I need to get rid of the corresponding entries in the child table. I need to do this in a procedure and is based off of the primary key of the parent table. As of right now I am just confused on what input parameters I need. This is what I have so far:
procedure sps_delete_patientmedrecs_det (
p_parentPK_in in parent_table.parentPK%type,
p_err_code_out out number,
p_err_msg_out out varchar2)
delete from child_table
where child_table.childFK = p_parentPK_in;
delete from parent_table
where parent_table.parent.parentPK = p_parentPK_in;
end;
As of right now I dont think this would work because I dont think the procedure would know what the child foreign key is. I thought of doing a select statement but then I’m confused on the input paremeters would be since I am only getting p_parentPK_in. Any help is appreciated and thank you in advance.
Also as a footnote, DELETE CASCADE isnt in the picture.
Nevermind, that worked. I just added another begin before the second delete.