最好,角色名用一个@变量保存, 我只要修改变量的值,就可以使用.谢谢!

解决方案 »

  1.   

    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