When naming tables, you have two options – to use the singular for the table name or to use a plural. My suggestion would be to always go with names in the singular. If you're naming entities that represent real-world facts, you should use nouns. These are tables like employee, customer, city, and country.
It's a pretty established convention that database table names, in SQL at least, should be singular. SELECT * FROM user; See this question and discussion. It's also a pretty established convention that RESTful API resource names should be plural.
There are four main types of JOINs in SQL: INNER JOIN, OUTER JOIN, CROSS JOIN, and SELF JOIN.
It seems like the mapping table is storing all the roles that each user is a member of. If this is correct I would call the table UserRoles
.
This correctly (IMO) pluralizes the intent of the table rather than UsersRoles
which just sounds odd.
I'd call the users table User
, the roles table Role
and the join table UserRoles
.
By the way, the pk Id
is not really necessary in a join table. Better make the UserId
and RoleId
together the pk or just uk (unique key) so that you can ensure unique User
-Role
relationships.
I would suggest simply UsersRoles, as that is what it holds.
User
or Users
? What about things that end in an S? etc" (I would change this now if you just started the project)User
, Role
, and the xref table: UserRole
.UserRole
makes much more sense than RoleUser
.User_X_Role
or UserXRole
as well, if you like the extra verbosityThe database represents am enterprise, right? So what do the people in that enterprise call the relationship?
Here are some I do know:
employee
reports to line manager
== org chart
student
takes course
== enrolment
woman
marries man
== marriages
When in doubt, ask a domain expert within the enterprise.
I'd call the link table this:
Remove_The_Surrogate_Primary_Key_From_The_Link_Table_Unless_You_Can_Prove_That_You_Really_Need_One
We have the same structure and call the link table UserRoles.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With