您当前的位置:首页 > 计算机 > 软件应用 > 数据库 > 其它数据库

查询用户权限的SQL语句

时间:02-19来源:作者:点击数:

查询用户权限的SQL语句

下面以用户ID为1的用户为例,讲解查询用户权限的SQL语句写法。

1. 从用户的角色表中查询用户权限(去掉重复记录)

select

distinct(e.AUTHKEY)

from USER a

left join USER_ROLE b on a.USERID=b.USERID

left join ROLE c on b.ROLEID=c.ROLEID

left join ROLE_AUTHORITY d on c.ROLEID=d.ROLEID

left join AUTHORITY e on d.AUTHID=e.AUTHID

where a.USERID = 1;

2. 从用户的组角色表中查询用户权限(去掉重复记录)

select

distinct(f.AUTHKEY)

from USER a

left join GROUP_USER b on a.USERID=b.USERID

left join GROUP_ROLE c on b.GRPID=c.GRPID

left join ROLE d on c.ROLEID=d.ROLEID

left join ROLE_AUTHORITY e on d.ROLEID=e.ROLEID

left join AUTHORITY f on e.AUTHID=f.AUTHID

where a.USERID = 1;

3. 联合用户的角色表和组角色表查询用户权限(去掉重复记录)

select

distinct(e.AUTHKEY)

from USER a

left join USER_ROLE b on a.USERID=b.USERID

left join ROLE c on b.ROLEID=c.ROLEID

left join ROLE_AUTHORITY d on c.ROLEID=d.ROLEID

left join AUTHORITY e on d.AUTHID=e.AUTHID

where a.USERID = 1

union

select

distinct(f.AUTHKEY)

from USER a

left join GROUP_USER b on a.USERID=b.USERID

left join GROUP_ROLE c on b.GRPID=c.GRPID

left join ROLE d on c.ROLEID=d.ROLEID

left join ROLE_AUTHORITY e on d.ROLEID=e.ROLEID

left join AUTHORITY f on e.AUTHID=f.AUTHID

where a.USERID = 1;

方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门