/*
** ELIMINA TODOS LOS USUARIOS DE LA BASE DE DATOS DYNAMICS
** ELIMINA EL GRUPO DYNGRP Y LO RECREA
*/
declare @cStatement varchar(255) /* Misc exec string */
declare @DynDB varchar(15) /* DB Name exec string */
declare @DYNGRPgid int /* Id of DYNGRP group */
/*
** Elimina todos los usuario del role DYNGRP
*/
SET QUOTED_IDENTIFIER OFF
use DYNAMICS
select @DYNGRPgid = (select gid from sysusers where name = ‘DYNGRP’)
declare G_cursor CURSOR for select «sp_dropuser [» + name+»]» from sysusers
where gid = @DYNGRPgid and name <> ‘DYNGRP’
set nocount on
OPEN G_cursor
FETCH NEXT FROM G_cursor INTO @cStatement
WHILE (@@FETCH_STATUS <> -1)
begin
EXEC (@cStatement)
FETCH NEXT FROM G_cursor INTO @cStatement
end
DEALLOCATE G_cursor
/*
** Do not delete the group to attempt to preserve the permissions already
** granted to it.
*/
use DYNAMICS
if exists (select gid from sysusers where name = ‘DYNGRP’)
begin
exec sp_dropgroup DYNGRP
end
/*
**RECREA LOS USUARIO DEL ROLE DYGRP
*/
use DYNAMICS
if not exists (select name from sysusers where name = ‘DYNGRP’)
begin
exec («sp_addgroup DYNGRP»)
end