N:N question

  • Hello, please consider a role based security system with Users and Roles. The db needs to support the following scenario:

    * User1 should have Role1 and Role2

    * User2 should have Role1 and Role2

    So the system should be able to associate many users to many roles and the same roles should be shareable among many users.

    I would create a UserRole table in a N:N relationship to support this scenario. Will you please confirm that this is the correct design and will you please provide an example and rationale where this design should instead be implemented as a 1:N (User:Role) relationship?

  • This is the simplest way

    😎

    [User]-|---0<[UserRole]>0---|-[Role]

  • Thanks Eirikur, that's the basic N:N implementation I had in mind. My question was, is N:N the correct relationship for the scenario I'm describing, and under what scenario would I need to implement this relationship as 1:N?

  • sqlguy-736318 (5/8/2014)


    Thanks Eirikur, that's the basic N:N implementation I had in mind. My question was, is N:N the correct relationship for the scenario I'm describing, and under what scenario would I need to implement this relationship as 1:N?

    What you described is a N:N relationship, if you are looking for any kind of justification for a 1:N relationship in this context consider this (N)1:N;-)

    😎

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply