nmccrina
October 14th, 2009, 01:33 AM
This is for a school-planning application I'm writing. I'll try to make it understandable :P I'm pretty much a n00b when it comes to databases, though I think today something finally clicked and I made some progress. :)
I have a database table of students. I would like to keep track of which courses a student is currently taking, but cannot figure out how to store this information in the database. The best idea I've had is adding columns to the table like 'course_one', 'course_two' etc., but this isn't optimal as it imposes a limit on the number of courses a student can take at once and also makes queries awkwarder (more awkward?) like:
SELECT student.last_name, student.first_name, course.name
FROM student, course
WHERE course.name = 'science' AND (course.name = student.course_one OR course.name = student.course_two OR course.name = student.course_three OR course.name = student.course_four
This to list the students that are taking science at the moment. Any suggestions on the best database design to go with here? Is a database even the best way to go? My dad (a programmer, but by his own admission with little experience in databases) suggested XML, which is tempting because I at least understand it halfway decently (you cant't really get any more basic than XML!).
I have a database table of students. I would like to keep track of which courses a student is currently taking, but cannot figure out how to store this information in the database. The best idea I've had is adding columns to the table like 'course_one', 'course_two' etc., but this isn't optimal as it imposes a limit on the number of courses a student can take at once and also makes queries awkwarder (more awkward?) like:
SELECT student.last_name, student.first_name, course.name
FROM student, course
WHERE course.name = 'science' AND (course.name = student.course_one OR course.name = student.course_two OR course.name = student.course_three OR course.name = student.course_four
This to list the students that are taking science at the moment. Any suggestions on the best database design to go with here? Is a database even the best way to go? My dad (a programmer, but by his own admission with little experience in databases) suggested XML, which is tempting because I at least understand it halfway decently (you cant't really get any more basic than XML!).