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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:11:55+00:00 2026-05-24T06:11:55+00:00

This is the database schema we have. t_RoleCombinations – These are all possible combination

  • 0

This is the database schema we have.

DB Schema

t_RoleCombinations – These are all possible combination of Permissions a Role can have.

t_Permissions_Hierarchy – This enforces permissions. For e.g. if a role has permissions to Create some reosource, it should have the permissions to Edit that resource and if has permission to Edit it should have the permission to View. We also have a Share permission which if assigned should also enforce View permission. So, if a role has Create permission, it should also have View but might not have Share permission. Because of this complexity we cannot enforce hierarchy in a tree-view manner by having a ParentPermissionId column in t_Permissions and that is why have this t_PermissionHierarchy table.

t_RoleCombinations_Permissions – this is mapping table which actually defines all the combinations of permissions.

Sample data of t_Permissions table

Sample Data of t_Permissions table

Sample data of t_PermissionsHierarchy table

Sample data of t_PermissionsHierarchy table

When the client updates a Role, on the server I get a set of permissions which I need to match with one of the set in t_RoleCombinations_Permissions table and get a RoleCombinationId for it to be updated in t_Roles table. A comma separated value for set of permissions is passed in SP through parameter and I can make it recordset by a table valued function similar to the one stated here if need be.

UPDATE:-

-I thought of creating a Varchar(Max) column in t_RoleCombinations to store comma separated sorted PermissionIds. But that’s not good in a relational database.

-The statement I could think is below. But it won’t work as IN operator checks logical OR and not AND.

SELECT RoleCombinationId from t_RoleCombinations_Permissions
WHERE PermissionId in (1,2,3,4,5) -- my comma saperated permissions
GROUP BY RoleCombinationId
HAVING Count(*) = 5 -- number of permissions specified.
  • 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-05-24T06:11:57+00:00Added an answer on May 24, 2026 at 6:11 am

    I’m answering my own question. This is how I finally did it.

    In this all code below, @permisionSet is this table variable into which all the comma separated permisionIds are inserted.

    DECLARE @permissionSet TABLE (Id int, PermissionId bigint)
    

    This is how I match the set of permissions with the combination already available. I got this idea from another question.

    SELECT @roleCombinationId = ISNULL(match.RoleCombinationId,0)
      FROM (
        SELECT RoleCombinationId
        FROM t_RoleCombinations_Permissions
        WHERE PermissionId IN (SELECT PermissionId FROM @permissionSet)
        GROUP BY RoleCombinationId
        HAVING COUNT(*) = @countt
      ) AS match
      INNER JOIN t_RoleCombinations_Permissions rcp ON match.RoleCombinationId = rcp.RoleCombinationId
      GROUP BY match.RoleCombinationId
      HAVING COUNT(*) = @countt
    

    And this is how I validate a set of permissions against the hierarchy restrictions set in t_PermissionHierarchy table.

    --If given set of permissions are valid
    IF(
        NOT EXISTS( SELECT ph.PermissionId
                    FROM @permissionSet ps
                    INNER JOIN t_PermissionHierarchy ph ON ph.PermissionId = ps.PermissionId
                    WHERE ph.ShouldHavePermissionId NOT IN (SELECT PermissionId FROM @permissionSet)
                   )
       )
    BEGIN
      --Permission set is valid. Insert it in t_RoleCombination_Pemissions table
    END
    

    And to find out which permissions are required but are missing in the set.

      WITH InvalidPerms AS (
        SELECT ph.PermissionId, ph.ShouldHavePermissionId
        FROM @permissionSet ps
        INNER JOIN t_PermissionHierarchy ph ON ph.PermissionId = ps.PermissionId
        WHERE ph.ShouldHavePermissionId NOT IN (SELECT PermissionId FROM @permissionSet)
        UNION ALL
        SELECT phh.PermissionId, phh.ShouldHavePermissionId
        FROM InvalidPerms ip
        INNER JOIN t_PermissionHierarchy phh ON phh.PermissionId = ip.ShouldHavePermissionId
        WHERE phh.ShouldHavePermissionId NOT IN (SELECT PermissionId FROM @permissionSet)
      )
      SELECT ShouldHavePermissionId FROM InvalidPerms
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a database schema like this: Users UserId RoleUserXRef RoleUserId RoleId UserId
I have an Oracle account (schema) of a remote Oracle database. By using this
Ever wonder what wikipedia's database schema looks like? I recently read this thread from
Given a table named person (in a MySQL database/schema), kind of like this one:
I have this legacy database for which I'm building a custom viewer using Linq
This is probably the most classic database problem. I have an E-commerce software solution
I'm trying to build a Hibernate layer for a database schema I have essentially
Is it possible to generate a schema of a database from nHibernate, where I
This database will store a list of children. But the problem is, they will
I'm using this database where the date colomn is a numeric value instead of

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.