可以啊,建一些相关表。就可以实现:
举例:--测试数据
create table 角色表(RoleID int,RoleName varchar(10))
insert into 角色表
select 1,'Admin'
union all select 2,'cwb'
union all select 3,'manage'create table 权限表(RightID int,RightName varchar(50))
insert into 权限表
select 1,'M1_Browser'
union all select 2,'M1_Add'
union all select 3,'M1_Modify'
union all select 4,'M1_Delete'
union all select 5,'M1_Print'
union all select 6,'M2_Browser'
union all select 7,'M2_Print'
union all select 8,'M3_Browser'
union all select 9,'M3_Add'
union all select 10,'M3_Modify'
union all select 12,'M3_Print'create table 角色权限表(RoleID int,RightID int)
insert into 角色权限表
select 1,1
union all select 1,2
union all select 1,3
union all select 1,6
union all select 2,6
union all select 2,7
go--创建显示的存储过程
create proc p_show
@RoleName varchar(10)
as
select 模块=模块
 ,browser=max(case 权限 when 'browser' then 1 else 0 end)
 ,[Add]=max(case 权限 when 'Add' then 1 else 0 end)
 ,[Modify]=max(case 权限 when 'Modify' then 1 else 0 end)
 ,[delete]=max(case 权限 when 'delete' then 1 else 0 end)
 ,[print]=max(case 权限 when 'print' then 1 else 0 end)
from(
select 模块=left(RightName,charindex('_',RightName)-1)
,权限=substring(RightName,charindex('_',RightName)+1,50)
from 角色权限表 a
join 权限表 b on a.RightID=b.RightID
where RoleID=(select RoleID from 角色表 where RoleName=@RoleName)
) a group by 模块
go--创建保存的存储过程
create proc p_save
@RoleName varchar(10), --要保存的角色名称
@tbname sysname, --用户选择处理后的结果表名
@deletetable bit=1 --处理完成后是否自动删除结果表,1.(默认)自动删除 0.不删除
as
declare @RoleID int,@s nvarchar(4000)
select @RoleID=RoleID from 角色表 where RoleName=@RoleName
SET XACT_ABORT ON 
begin tran
delete 角色权限表 where RoleID=@RoleID
set @s='insert into 角色权限表(RoleID,RightID)
select @RoleID,a.RightID 
from 权限表 a join(
select RightName=模块+''_browser'' from ['+@tbname+'] where browser=1
union all select 模块+''_Add'' from ['+@tbname+'] where [Add]=1
union all select 模块+''_Modify'' from ['+@tbname+'] where [Modify]=1
union all select 模块+''_delete'' from ['+@tbname+'] where [delete]=1
union all select 模块+''_print'' from ['+@tbname+'] where [print]=1
) b on a.RightName=b.RightName'
exec sp_executesql @s,N'@RoleID int',@RoleID
if @deletetable=1 exec('drop table ['+@tbname+']')
commit tran
go--创建临时表表,保存显示结果
create table #t(模块 varchar(10),browser bit,[Add] bit,[Modify] bit,[delete] bit,[print] bit)
insert into #t exec p_show 'admin'--修改权限
update #t set browser=1,[Add]=1,[Modify]=1--进行权限保存
exec p_save 'admin','#t'--显示保存结果
exec p_show 'admin'
go--删除测试环境
drop table 角色表,权限表,角色权限表
drop proc p_show,p_save