1

Usually, join (many to many) tables are named after the types they join - if a table joins users to roles, its name would contain both user and role (i.e. user_role).

Is there a naming convention that defines which word / type should come first?


EDIT: Having a convention means knowing the name without having to remember it. Please, try to understand that before voting for closing the question for being not constructive.

17
  • 1
    If it is one to many (many roles for one user), probably user would come first. If it is many to many, I don't think it matters at all. This is subjective though - certain frameworks like Ruby on Rails have important conventions for this kind of thing, but it is really up to you if you are not constrained by conventions like that. Jan 20, 2013 at 22:22
  • Subjective; just be consistent. I have seen "A_B" (alphabetically sorted), but I prefer "Primary_Secondary" where there is such a natural relationship: e.g. User is the "primary" subject/noun. Also, I prefer plural forms, so I would have "users_roles".
    – user166390
    Jan 20, 2013 at 22:23
  • 1
    @EmanuilRusev And conventions are subjective (which are generally "Not Constructive" when asked in questions) - there is no Defacto-Guide for SQL/MySQL in this regard :-) Book A will say do it this way, and Advocate B will say to do it that way.
    – user166390
    Jan 20, 2013 at 22:26
  • 1
    @pst, I know it is. I'm looking for arguments that would help me (and, hopefully, not just me) decide wich convention I should go for. Jan 20, 2013 at 22:30
  • 1
    @pst Precisely, and that's why I CV'd as not constructive :) Jan 20, 2013 at 22:39

1 Answer 1

2

In 1:n it is user_role.

In m:n I'd use the more important one first, and in this case the stronger term is user IMHO, as you usually assign roles to users, not vice-versa.

The role does not make sense without a user, but a user makes sense without a role.

Not the answer you're looking for? Browse other questions tagged or ask your own question.