Regarding deleting a course

Regarding deleting a course

by dev moodle -
Number of replies: 0
I have installed programs plugin in my moodle.
So, as we know that we can add and remove course to a program and allocate them to users.
If I am deleting a course, it is getting deleted from the course table(by default, they are using delete_course($course), but it is not getting deleted from the table enrol_programs_items.
As a result, even if the course is deleted, it is still showing it in the list of courses in a program [site administration->programs->program management->open a program]
So, can you please help me to write SQL query such that it reflects the deletion in enrol_programs_items table also.
DELETE FROM enrol_programs_items WHERE courseid = [courseid];
I'm thinking to convert this in moodle format 
Or suggest me what would be best in this case.
Thanks in advance.
Average of ratings: -