lunes, 3 de marzo de 2008

Copiar permisos de un usuario

Os pongo un sencillo script que puede ser de utilidad si queremos copiar los permisos que un usuario tiene sobre los distintos objetos de una bbdd del tipo:

Grant References ON XTable TO user GO
Grant Select ON XTable TO user GO

El script genera a su vez otros scripts para poder reproducir estos permisos en otra bbdd



use db
go

create table #dba_user_rights(
Owner sysname,
Object sysname,
Grantee sysname,
Grantor sysname,
ProtectType char(10),
Action varchar(20),
Columna sysname
)

insert into #dba_user_rights EXEC ('sp_helprotect NULL, ''usuario''')


select protecttype + ' ' + action + ' ON ' + object + ' TO ' + grantee + ' GO 'from #dba_user_rights


drop table #dba_user_rights

3 comentarios:

Anónimo dijo...

Sos un genio el script esta genial, excelente muchas gracias

SqlAst dijo...

gracias; me alegra te haya resutlado útil

MigueSabinero dijo...

groso!! me ayudo muchisimo, gracias!!