I'm not sure about doing this with SQL alone but it should be fairly easy to write a CLI script to add it.
You can get a list of all the courses that don't have the enrolment plugin by something like this:
SELECT c.id FROM mdl_course c LEFT JOIN mdl_enrol e ON c.id = e.courseid AND e.enrol = 'self' WHERE e.id IS NULL AND c.id <> :siteid
Then loop through the courses and use $plugin->add_default_instance($courseid) to add it (where $plugin = enrol_get_plugin('self'));