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 561659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:28:22+00:00 2026-05-13T12:28:22+00:00

My database has two tables, one contains a list of users, the other a

  • 0

My database has two tables, one contains a list of users, the other a list of roles. Each user will belong to one or more roles, and of course each role will have multiple users in it.

I’ve come across two ways to link the information. The first is to add a third table which contains the ID’s from both tables. A simple join will then return all the users that belong to a role, or all the roles to which a user belongs. However, as the database grows, the datasets returned by these simple queries will grow exponentially.

The second method is to add a column to the users table in which a delimited list of roles is stored. This will eliminate the need for the third linking table, which may have a positive effect on database growth. The downside is that SQL does not have the ability to use delimited lists. The only way I’ve found to process that information is to use a temporary table and a custom function.

Is viewing my execution plans, the “table scan” event is the one that takes the most resources. It makes sense that eliminating a table from the equation would speed things up. The function takes up less than 1% of the resources.

These tests were done on a database with less than 20 records. As the size of the database grows, the table scans will take longer, so perhaps limiting them is the best choice.

If using the delimited list is a good way to go, why is nobody doing it?

Please tell me which is your preferred method (even if it’s different from my two) and why.

Thank you.

  • 1 1 Answer
  • 1 View
  • 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-05-13T12:28:22+00:00Added an answer on May 13, 2026 at 12:28 pm

    If you have a delimited list, finding users with a given role is going to become very expensive: effectively, you need to do a FULL scan of that table, and look at all the values for that column in every row, trying to see if it contains a given role.

    A separate table (normalized, many to many relation) is the way to go, and with proper indexing you will not have full scans happening.

    eg:

    User:  UserId, Name, ....
    Role:  RoleId, Name, ....
    UserRole:  UserRoleId, UserId, RoleId
    

    (UserRoleId is optional, you could alternatively have the PK be UserId+RoleId, I won’t get into the discussion here of surrogate vs compound keys here)

    You’ll want an index on (UserId, RoleId) that is UNIQUE, to enforce no duplicates. This will also help with any queries where you’re trying to see if a specific user has a specific role (WHERE userId = x AND roleId = y)

    If you are looking up all the roles a user has, you’ll want an index on just UserId.

    Conversely, if you are looking up all the users a given role has, an index on just roleId will speed that up. If you don’t do this query, or do it very rarely, then not having this index will speed up performance slightly for insert/updates, as it is one less thing to do. This is the careful balancing act that is database tuning.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database that has two tables, one of which contains a foreign
I have a database with two tables. One of the tables contains users, the
I have two tables in the database one contains a list of all possible
One of my tables in my SQL database has a growth rate of two
I have two databases named: DB_A and DB_B . Each database has one collection
I'm working on a SQL Server 2008 database. This database has two tables. Book
I have a database framework where I have two tables. The first table has
My database has two types of entries: The very dynamic (users, comments, etc) and
I'm wanting to update a record in my database which has two values, one
I have a database with two tables, ProductLine and Supplier. ProductLine contains the foreign

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.