User, role, rights database design

Source: Internet
Author: User

Rights Management

Rights management, mainly the relationship between people and permissions, but if people directly and permissions to deal with, then the assignment of permissions, permissions revocation and change of permissions will be very troublesome, so introduced, role, assign permissions to the role, and then assign roles to the user.

This design mainly involves 6 sheets,

User tables (to store all information about a user)

Permission table (to store all permissions)

Role table (for storing all roles)

Association tables for users and roles (association of users and roles)

Association tables for roles and permissions (associations of roles and permissions)

Menu table (which is associated with permissions, mainly for practical use)

User table

CREATE TABLE [dbo]. [Users] (    [UserID] [int.] IDENTITY () not NULL,    [UserName] [nvarchar] (primary key,--account    [Password] [nvarchar] ( [Userdspname] [nvarchar] (+), [    Sex] [char] (1),    [Birthday] [datetime],    [Phone] [nvarchar] (20)  ,    [Email] [nvarchar] (+),    [EmployeeID] [nvarchar] (+), [    Activity] [bit],--available    [usertype] [char] (2),    [Style] [ NVARCHAR] (50))

Permission table:

CREATE TABLE [dbo]. [Permission] (    [PermissionID] int identity,    [Description] [nvarchar] (50)--permission name)

Role table:

CREATE TABLE [dbo]. [Roles] (    [Roleid] [int] IDENTITY,    [Description] [nvarchar] (200)--Role name)

Association tables for users and roles:

CREATE TABLE [dbo]. [Userroles] (    [UserID] [int] NOT NULL,--user ID    [roleid] [int] NOT NULL,--permission ID CONSTRAINT [pk_userroles] PRIMARY KEY CLUSTERED (    [UserID] ASC,    [Roleid] ASC) with (Ignore_dup_key = OFF) on [PRIMARY]) on [PRIMARY]

Associated tables for roles and permissions:

CREATE TABLE [dbo]. [Rolepermissions] (    [Roleid] int not  null,--role ID    [Permissionid]int NOT NULL,--permission ID CONSTRAINT [pk_rolepermissions] PRIMARY KEY CLUSTERED (    [Roleid] ASC,    [PermissionID] ASC) with (Ignore_dup_key = OFF) on [PRIMARY]) on [PRIMARY]

Menu table:

CREATE TABLE [dbo]. [Menu] (    [ID] [int] IDENTITY () not NULL,    [textch] [nvarchar] (+)  null,--menu in Chinese    [texten] [nvarchar] (200  null,--The English name of the menu    [parentid] [int] NULL,--parent node    [OrderID] [int] null,--sort under the same parent node    [URL] [nvarchar] ( ,--menu for Permissions    [PermissionID] [int] NULL,--permission ID    [IMAGEURL] [nvarchar] (null--menu picture link) on [PRIMARY]

User, role, rights database design

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.