Este script simplemente ejecuta sp_change_users_login con la opción 'auto_fix' de manera automática para cada uno de los usuarios huérfanos de una bbdd
declare @usr varchar(100)
declare @cmd varchar(100)
declare cur insensitive cursor for
select name as 'Usuario' 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 Cur
fetch next from Cur into @usr
while @@fetch_status=0
begin
select @cmd=' sp_change_users_login ''auto_fix'', '''+@usr+''' '
exec(@cmd)
fetch next from Cur into @usr
end
close Cur
deallocate Cur
No hay comentarios:
Publicar un comentario