1

I'm working on a "e-class" application, where you have admins,teachers,students and lessons. One student can have many teachers and many lessons, one teacher can have many students and many lessons, and one lesson can have one teacher but many students.

I want to make it so admins have their own login page, and the teachers/students share the same. (btw, is this the best approach?)

My question is, should I put all the login related info (username,password,email) into a "users" table, and have seperate tables("teachers","students") for all the rest info?

Should I include a key on the "users" table that points to the primary id of either the "students"/"teachers" table?

What would be the best approach to all of these? Help me out, mysql gurus :)

NOTE: I've seen many questions related to mine, but none of them really answered my question.

4
  • Is there any difference between the info you will be storing for students vs info stored for teachers? Commented Jan 25, 2013 at 18:30
  • yes, each student has a unique parentCode, along with the register date and the semester they are in. Commented Jan 25, 2013 at 18:36
  • Does a student get a new record created every semester? Commented Jan 25, 2013 at 18:39
  • no, it's semester field gets updated each time. (btw thanks for your interest :) ) Commented Jan 25, 2013 at 18:40

1 Answer 1

1

I would go a step further than Abe Miessler suggests, and create a reference table between Users and Roles.

For example, it is not impossible that a teacher might enroll as a student, and thus be required to assume both roles at different times.

USER_TABLE:
UserID PK
UserName
OtherUserData

ROLE_TABLE
RoleID PK
RoleName

USER_ROLES
UserID PK
RoleID PK

USER_ROLES has composite PK on UserTable.UserID AND RoleTable.RoleID
Sign up to request clarification or add additional context in comments.

3 Comments

Just as an aside, and definitely not required, but I often would pk the cross reference table (user_roles here) because it can often make it way easier to deal with some orms that way. +1 to your solution though
@Horus - Yeah, I've done the same thing. Also might even put an "Enabled" bit field on there, in case there is a reason to enable/disable without actually removing access.
Seems like I hadn't marked this as correct, well here you go :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.