Permission Database Design (SQL Server)

Source: Internet
Author: User

Personal summary, for reference only !!! Suitable for small websites !!!
Five database tables are used to create roles and permissions:
1. User information table
Create table employee
(
Userid varchar (50) not null, -- User ID
Username varchar (100), -- User Name
Userpassword varchar (100), -- Password
..
..
..
..
)
Alter table employee -- primary key
Add constraint pk_employee_userid primary key (userid)
2. Role table
Create table role
(
Roleid varchar (50) not null, -- Role Id
Rolename varchar (100), -- role name
)
Alter table tole -- primary key
Add constraint pk_role_roleid primary key (roleid)
3. Permission table
Create table popedom
(
Popedomid int identity (1, 1) not null, -- permission Id
Popedomname varchar (100), -- permission name
Popedomfatherid int, -- permission parent ID
Popedomurl varchar (100) -- connection path of the tree
..
..
)
Er table popedom -- primary key
Add constraint PK_popedom primary key (popedomid)

Add data as shown in Figure
Insert into popedom values ('My desk ', 0 ,'')
Insert into popedom values ('email address', 1, '../mail/EmaiolManage. aspx ')
(The principle of adding data is that the popedomfatherid of the first-level contact is 0. If it is a contact under (my desk), their popedomfatherid is the primary key of the (my desk)

4. user-role relationship table
Create table user_role
(
Connectionid int identity (1, 1) not null, -- Link ID
Userid varchar (50) not null, -- administrator table ID
Roleid varchar (50) not null -- Role Id
)
Alter table user_role -- primary key
Add constraint PK_admin_role primary key (connectionid)
5. Role-Permission relationship table
Create table role_popedom -- Role and permission table
(
Connectionid int identity (1, 1), -- Link Id
Roleid varchar (50) not null, -- Role ID
Popedomid int not null, -- permission Id
Popedom int -- permission (1 is available, 2 is unavailable)
)
Alter table role_popedom -- primary key
Add constraint PK_role_popedom primary key (connectionid) -- primary key

1. the user information table is the basic user information table.
2. Role tables are the roles used in the system, such as system administrators and general managers ......
3. The permission table is built on a tree structure, which is generally managed by the background system administrator.
4. the user-role relationship table establishes a relationship between the user and the role.
5. The relationship table between roles and permissions establishes a relationship between roles and permissions.

Related Article

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.