The Course ID field on the Moodle course set up screen is used to associate the Moodle course with a course (subscription product) in the external database. In the external database you relate students to subscription products. In the external database a student could be enrolled in any or all subscription products. This really is a function of the external controlling program as to how a student can enroll into which program.
As far as a course ID string this would come into play when a given Moodle course is related to more than one subscription product in the external database.
For instance you might have MAT 101 in Moodle, but offer two subscription products to it in the external database such as "30 days access to MAT 101" and "90 days access to MAT 101" So in the external database you have two subscription products that relate to the same Moodle course. In this case you would need to use a course ID string to relate the one Moodle course to both subscription products in the external database.
As far as the nuts and bolts to how to set up the database I can't help you with that. When you say external database you really are referring to a stand alone program that will manage the users and class enrollment. This is best suited for a subscription/membership type script that saves the information in an external database that can be accessed by Moodle.
Good luck with this.