Adsense

Friday, May 1, 2015

Update use SIDS following a SQL Server Restore


declare @usrname varchar(100), @command varchar(100)
declare Crs insensitive cursor for
select name as UserName from sysusers
where issqluser = 1 and (sid is not null and sid <> 0x0)
and suser_sname(sid) is null
order by name
for read only
open Crs
fetch next from Crs into @usrname

while @@fetch_status=0
begin
select @command= 'exec sp_change_users_login @action ='+''''+ 'auto_fix' + '''' + ',@UserNamePattern='+''''+ @usrname+''''
print @command
exec(@command)
fetch next from Crs into @usrname
end
close Crs
deallocate Crs



No comments:

Post a Comment