0

im new to mysql, and my first project would be to create a database of students-classes scenario.

i have decided to make a table "students" then thought each student could possibly be a member of one or more classes, so in my mind there would be a column in the students table that says "classes" now what data type would be appropriate for that? a class would consist of a string for name, then schedule (MTh, 10:30-11:30). Or should i instead just make a "classes" table then one of the columns would contain all the names of the students that belong to that class, then what data type should be used for a long "list"-like strings?

1 Answers1

1

Each class can have many students, and each student can have many classes. Therefore your dilemma is whether to record the students in the classes table, or the classes in the students table.

In a relational database, you should have three tables:

  • one table for students;
  • one table for classes;
  • one table that has the pairings: one row each for one student being a member of one class.

It's far more flexible and general-purpose to do it this way.

See also my answer to Is storing a delimited list in a database column really that bad?

Community
  • 1
  • 1
Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
  • thank you for clearing that, now I need to read up on database management systems so I could properly model my database. – user1624025 Mar 25 '13 at 04:21
  • I recommend [SQL Antipatterns: Avoiding the Pitfalls of Database Programming](http://pragprog.com/book/bksqla/sql-antipatterns). ;-) – Bill Karwin Mar 25 '13 at 11:37