权限数据库设计(Sql Server)

个人总结,仅供参考!!!适合做小型网站时用!!!
创建角色与权限要用到五张数据库表:
1,用户信息表
create table employee
(
   userid varchar(50) not null,  --用户ID
   username varchar(100),    --用户名
   userpassword varchar(100), --密码
   ..
   ..
   ..
   ..
)
alter table employee        --主键
add constraint pk_employee_userid primary key (userid)
2,角色表
create table role
(
  roleid varchar(50) not null, --角色Id
  rolename varchar(100),        --角色名称
)
alter table tole     --主键
add constraint pk_role_roleid primary key (roleid)
3,权限表
create table popedom
(
  popedomid int identity(1,1) not null, --权限Id
  popedomname varchar(100), --权限名称
  popedomfatherid int,      --权限父ID
  popedomurl varchar(100)   --树的连接路径
  ..
  ..

er table popedom       --主键
add constraint PK_popedom primary key (popedomid)

添加数据如
insert into popedom values('我的办公桌',0,'')
insert into popedom values('电子邮箱',1,'../mail/EmaiolManage.aspx')
(添加数据的原则是一级接点的popedomfatherid 为0,如果是(我的办公桌)下面的接点,它们的popedomfatherid为(我的办公桌)的主键)

4,用户与角色关系表
create table user_role
(
 connectionid int identity(1,1) not null, --关系ID
  userid varchar(50) not null,   --管理员表ID
  roleid varchar(50) not null   --角色Id
)
alter table user_role    --主键
add constraint PK_admin_role primary key(connectionid)
5,角色与权限关系表
create table role_popedom     --角色与权限表
(
  connectionid int identity(1,1), --关系Id
  roleid varchar(50) not null,      --角色ID
  popedomid int not null,   --权限Id
  popedom    int   --权限 (1为可用,2为不可用)
)
alter table role_popedom       --主键
add constraint PK_role_popedom primary key(connectionid) --主键

1.用户信息表是用户基本信息表。
2.角色表是系统中所用到的角色,如系统管理员,总经理……
3.权限表这里建立的是树型结构的,一般都是后台系统管理员管理的那棵树。
4.用户与角色关系表是把用户和角色建立一种关系。
5.角色与权限关系表是角色与权限建立一种关系。

posted @ 2008-06-28 13:32  factly  阅读(981)  评论(0编辑  收藏  举报