Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8046555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:49:21+00:00 2026-06-05T05:49:21+00:00

I want to design a user/role system: The users have a name and a

  • 0

I want to design a user/role system:

The users have a name and a password and then the user can have several roles like Admin.

For this I created a schema like this:

Users:

CREATE TABLE [dbo].[Users]
(
    [id] [int] NOT NULL,
    [name] [nvarchar](50) NULL,
    [password] [nvarchar](50) NULL,

    CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED ([id] ASC)
)

Roles:

CREATE TABLE [dbo].[Roles]
(
    [id] [int] NOT NULL,
    [name] [nvarchar](50) NULL,

    CONSTRAINT [PK_Roles] PRIMARY KEY CLUSTERED ([id] ASC)
)

user_roles:

CREATE TABLE [dbo].[User_Roles]
(
    [id] [int] NOT NULL,
    [User_id] [int] NOT NULL,
    [Role_id] [int] NOT NULL,

    CONSTRAINT [PK_User_Roles] PRIMARY KEY CLUSTERED ([id] ASC)
)

My question is: should I use foreign keys User_Roles.User_id -> User.Id

If yes why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:49:23+00:00Added an answer on June 5, 2026 at 5:49 am

    Not quite sure what you mean, but…

    • User_Roles should have 2 columns only User_id and Role_id
      Both of these form the Primary Key
    • You do not need an extra id column User_Roles
    • User_id is a foreign key to Users.id
    • Role_id is a foreign key to Roles.id

    Edit: Now I understand. Yes, always use foreign keys

    Also…

    • if password is nvarchar(50), this implies plain text. This is bad.
    • if you have duplicate name values in Users, how do you know which user is which?
      Especially if they have the same password (which will happen because we meatsacks are stupid)

    Edit after comment after primary key creation…

    CREATE TABLE [dbo].[User_Roles]
    (
        [User_id] [int] NOT NULL,
        [Role_id] [int] NOT NULL,
    
        CONSTRAINT [PK_User_Roles] PRIMARY KEY CLUSTERED ([User_id], [Role_id]),
        CONSTRAINT [UQ_ReversePK] UNIQUE ([Role_id], [User_id])
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to design a protocol between several components I have. each can run
I want to design a chat view like BlackBerry messenger (unfortunately new users are
I have a need to design a system to track users memberships to groups
I have a table of Users, Each USR_ID can have multiple Roles,Views,Brands and Units.
I want to design an app that needs user to input few things like
I want design a stored procedure / function creator program where user can create
i have some panel in page (Like Visual studio), i Want when user click
I want to design a rich text area for iPhone where user can enter
I want to design a c# program which can run program a 3rd exe
I want to design a database to store crossword puzzles, mainly I have 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.