I use the following SQL code (specific for MySQL) to create a test external database when I want to debug thins in that area (with a few hundreds record more, but you get the idea):
CREATE TABLE mdl_user_course_rol (
user varchar(32) default NULL,
course varchar(32) default NULL,
rol varchar(50) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO mdl_user_course_rol VALUES ('iarenaza', 'LD2011A', 'teacher');
INSERT INTO mdl_user_course_rol VALUES ('iarenaza', 'LD2011B', 'student');
INSERT INTO mdl_user_course_rol VALUES ('studa', 'LD2011A', 'teacher');
INSERT INTO mdl_user_course_rol VALUES ('studa', 'LD2011B', 'student');
INSERT INTO mdl_user_course_rol VALUES ('admin', 'LD2001A', 'editingteacher');
The value of the 'user' column is matched againt the user 'username' value, the 'course' column is matched against the course 'shortname' value and the 'rol' column against the rol 'shortname' value.
Saludos. Iñaki.