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

  • SEARCH
  • Home
  • 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 8878895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:49:23+00:00 2026-06-14T19:49:23+00:00

I have the following structure: — Table Users — – User1 – User2 –

  • 0

I have the following structure:

-- Table Users ---
-  User1
-  User2
-  User3

-- Table Roles ---
-  Role1
-  Role2
-  Role3
-  Role4

Every user has to have one row, not more or less. Should i create a new table, eg. `user_roles” and store the users role in there, like:

-- Table user_roles --
-  user_id = User1     role_id = Role2
-  user_id = User2     role_id = Role1
-  user_id = User3     role_id = Role4

Or, should I store the users role in the Users table? Since there will always only be one role for each user, I see no reason why not to keep it in the Users table. Am I thinking correctly or should it be in a separate table? Very simple question, but I’ve wondered for long. In the past I have kept the “key” in the Users table.

  • 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-14T19:49:24+00:00Added an answer on June 14, 2026 at 7:49 pm

    To enforce that every use has to have exactly one role, you should add a role_id to the users table, make it not null and reference the roles table

    create table roles 
    (
      id integer primary key,
      role_name varchar(50) not null
    );
    
    create table users
    (
       id integer not null primary key,
       username varchar(50) not null,
       role_id integer not null,
       ... other columns ...
    );
    alter table users 
       add constraint fk_users_rol 
       foreign key (role_id) references roles(id);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following table structure: Entity --------------------- id | name Users --------------------- id |
I have following table structure in my DB ID Name -------------------------- ID_1 Name1 ID1
I have following Table Structure : Table: CashStatus (Can have duplicate entries for ATM)
I have following table structure table domains ID | name | ________________________ 1 |
I have the following structure in my UI <ScrollView android:id=@+id/vscroll android:layout_width=match_parent android:layout_height=match_parent> <TableLayout android:id=@+id/table
I have following table structure <table> <tbody> <tr> <td>Lorem</td> <td>Ipsum</td> <td>Fierent</td> </tr> <tr> <td>Lorem
I have following table structure ID Name Parent_ID 1 abc 0 2 efg 1
I have following table structure: uid | product_code --------------------- 00001 | 'tb' 00001 |
I have following structure <table> <tr> <td><img class='show_detail'></td> <tr> <tr class='detail'> <td>XYZ</td> <tr> <tr>
I have following db structure in mysql. Table: Story Id Name categoryid date 1

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.