dbTalk Databases Forums  

Script to copy permissions for all objects given to a user or a role

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Script to copy permissions for all objects given to a user or a role in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
gudia
 
Posts: n/a

Default Script to copy permissions for all objects given to a user or a role - 07-07-2004 , 05:38 PM






How would I, using a sql script, copy permissions assigned to a user
or a role in one or more databases to another user or a role in their
respective databases?

Help appreciated

Reply With Quote
  #2  
Old   
Simon Hayes
 
Posts: n/a

Default Re: Script to copy permissions for all objects given to a user or a role - 07-08-2004 , 03:01 AM






gudia97 (AT) yahoo (DOT) com (gudia) wrote in message news:<2130f7ff.0407071438.275b76f3 (AT) posting (DOT) google.com>...
Quote:
How would I, using a sql script, copy permissions assigned to a user
or a role in one or more databases to another user or a role in their
respective databases?

Help appreciated
First of all, I would avoid granting permissions to users, since this
becomes difficult to manage - if you always use roles, then things are
much easier. Even if you have only one user in a role today, at least
you won't have any extra work when you need to add a second one. Also,
you should keep a permissions script for each role, so you know which
permissions are correct, and you can run it for multiple roles.

To solve your issue right now, you could add one role to another, if
that's appropriate. If not, then you can reverse-engineer a
permissions script using a query like this:

select
case protecttype
when 205 then 'grant '
when 206 then 'revoke '
end +
case action
when 26 then ' references '
when 193 then ' select '
when 195 then ' insert '
when 196 then ' delete '
when 197 then ' update '
when 224 then ' execute '
end +
' on ' + object_name(id) + ' to TargetRole '
+ case when protecttype = 204 then ' with grant option' else '' end
from
sysprotects
where
uid = user_id('SourceRole')

See sysprotects in Books Online for more information. Note that this
query doesn't handle SELECT or UPDATE permissions on explicit columns,
but only where the permissions are on the whole table. It also does
not handle statement permissions (CREATE TABLE etc.), but you can
easily write a similar query for that.

Simon


Reply With Quote
  #3  
Old   
billoo
 
Posts: n/a

Default Re: Script to copy permissions for all objects given to a user or a role - 07-08-2004 , 08:26 AM



Simon:

Thanks. This will help as a starting point. I do use roles as oppossed
to users for permissioning.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.