mssql server把数据库所有用户存储过程的EXEC权限赋另一角色

发布时间:2020-04-17  栏目:数据  评论:0 Comments

mssql server把数据库教程全数客商存款和储蓄过程的EXEC权限赋另一剧中人物

图片 1

declare @name varchar(8000)
declare cursor_a cursor for select  name from sysobjects  where
xtype=’U’
open  cursor_a
fetch next from cursor_a into @name
while @@fetch_status=0
begin 
  exec(‘delete from  ‘+@name)
  fetch next  from cursor_a into @name
end
close cursor_a
deallocate cursor_a

$sql=create procedure sp_GrantProce(@username varchar(40)) as begin
declare @user varchar(20),@name varchar(40) declare t_cursor cursor
for select user_name(uid) as users,name from sysobjects where (xtype=
‘P ‘ or xtype= ‘X ‘) and status 0 open t_cursor fetch next from
t_cursor into @user,@name while @@fetch_status=0 begin exec( ‘grant
execute on ‘+@user+ ‘. ‘+@name+ ‘ to ‘+@username) fetch next from
t_cursor into @user,@name end close t_cursor deallocate t_cursor
end go;

 1 table1布局如下
 2 id    int
 3 name  varchar(50)
 4 
 5 declare @id int
 6 declare @name varchar(50)
 7 declare cursor1 cursor for         –定义游标cursor1
 8 select * from table1               –使用游标的靶子(跟据需求填写select文卡塔尔
 9 open cursor1                       –张开游标
10 
11 fetch next from cursor1 into @id,@name  –将游标向下移1行,获取的多寡放入事情发生以前定义的变量@id,@name中
12 
13 while @@fetch_status=0           –判断是或不是中标获取数据
14 begin
15 update table1 set name=name+’1′
16 where id=@id                           –实行对应管理(跟据要求填写SQL文卡塔尔(قطر‎
17 
18 fetch next from cursor1 into @id,@name  –将游标向下移1行
19 end
20 
21 close cursor1                   –关闭游标
22 deallocate cursor1 

图片 2

留下评论

网站地图xml地图