查询用户权限的SQL语句

查询用户权限的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;

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

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;

  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
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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值