DeveloperJr
Programmer
Is there any command to do this without listing each table?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
declare @cmd nvarchar(1000)
declare @objname sysname
declare @owner sysname
declare @objtype char(2)
declare objs cursor for
select [name], user_name(uid) as owner, type from dbo.sysobjects
where type in ('U', 'V')
order by type, [name]
for read only
open objs
fetch next from objs into @objname, @owner, @objtype
while (@@FETCH_STATUS != -1)
begin
if (@@FETCH_STATUS != -2)
begin
select @cmd = 'grant ' +
case (@objtype)
when ('U') then ('select')
when ('V') then ('select')
end + ' on [' + @owner + '].[' + @objname + '] to [b]dyn_Risk'[/b]
exec (@cmd)
end
fetch next from objs into @objname, @owner, @objtype
end
close objs
deallocate objs
sp_MSforeachtable @command1="GRANT SELECT ON ? TO [b]user[/b]"
sp_MSforeachtable @command1="PRINT 'Granting select on ''?''' GRANT SELECT ON ? TO [b]user[/b]"