dbTalk Databases Forums  

How to Generate all grants to a user role? (SQL Server 2000)

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


Discuss How to Generate all grants to a user role? (SQL Server 2000) in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mark D Powell
 
Posts: n/a

Default How to Generate all grants to a user role? (SQL Server 2000) - 04-25-2007 , 03:19 PM






I had thought that I had posted this yesterday but since I cannot find
it here we go again.

I have searched the archives but either the code I want is not posted
or I missed it.

I have a user create role in a database that I need to reproduce in
another version of the database. Does anyone out there have the SQL
or T-SQL necessary to generate all the grants to a role?

-- Mark D Powell --


Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: How to Generate all grants to a user role? (SQL Server 2000) - 04-25-2007 , 04:46 PM






Mark D Powell (Mark.Powell (AT) eds (DOT) com) writes:
Quote:
I had thought that I had posted this yesterday but since I cannot find
it here we go again.

I have searched the archives but either the code I want is not posted
or I missed it.

I have a user create role in a database that I need to reproduce in
another version of the database. Does anyone out there have the SQL
or T-SQL necessary to generate all the grants to a role?
Not only you posted it yesterday, but I also replied yesterday. Let's
see if you are able to find the response this time:

The system table you need to look at is sysprotects. Here is a query
that gives the permissions for the most common commands. If you need
database permissions like CREATE TABLE, you will need to extend the
query below. I suspect that the id column has a special value in this
case; I have not investigated this myself.


SELECT CASE protecttype
WHEN 204 THEN 'GRANT'
WHEN 205 THEN 'GRANT'
WHEN 206 THEN 'DENY'
END + ' ' +
CASE action
WHEN 224 THEN 'EXECUTE'
WHEN 195 THEN 'INSERT'
WHEN 196 THEN 'DELETE'
WHEN 193 THEN 'SELECT'
WHEN 197 THEN 'UPDATE'
END + ' ON ' +
user_name(o.uid) + '.' + o.name +
' TO ' + user_name(p.uid)
FROM sysprotects p
JOIN sysobjects o ON p.id = o.id




--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #3  
Old   
Mark D Powell
 
Posts: n/a

Default Re: How to Generate all grants to a user role? (SQL Server 2000) - 04-26-2007 , 10:28 AM



On Apr 25, 5:46 pm, Erland Sommarskog <esq... (AT) sommarskog (DOT) se> wrote:
Quote:
Mark D Powell (Mark.Pow... (AT) eds (DOT) com) writes:

I had thought that I had posted this yesterday but since I cannot find
it here we go again.

I have searched the archives but either the code I want is not posted
or I missed it.

I have a user create role in a database that I need to reproduce in
another version of the database. Does anyone out there have the SQL
or T-SQL necessary to generate all the grants to a role?

Not only you posted it yesterday, but I also replied yesterday. Let's
see if you are able to find the response this time:

The system table you need to look at is sysprotects. Here is a query
that gives the permissions for the most common commands. If you need
database permissions like CREATE TABLE, you will need to extend the
query below. I suspect that the id column has a special value in this
case; I have not investigated this myself.

SELECT CASE protecttype
WHEN 204 THEN 'GRANT'
WHEN 205 THEN 'GRANT'
WHEN 206 THEN 'DENY'
END + ' ' +
CASE action
WHEN 224 THEN 'EXECUTE'
WHEN 195 THEN 'INSERT'
WHEN 196 THEN 'DELETE'
WHEN 193 THEN 'SELECT'
WHEN 197 THEN 'UPDATE'
END + ' ON ' +
user_name(o.uid) + '.' + o.name +
' TO ' + user_name(p.uid)
FROM sysprotects p
JOIN sysobjects o ON p.id = o.id

--
Erland Sommarskog, SQL Server MVP, esq... (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Yes, today I can find the thread. I am viewing the group via google
so I actually tried the Advanced Search option to hunt up the thread
but it came up empty.

Your query is much nicer that what I was about to resort to doing.
Using the EM generate code option under all tasks for a database I had
generated the DDL to a file. I was about ready to start filtering out
all the object DDL so that I would only have the grants left.

Modifying your query to work for a specific user should be easier.

Thanks.

-- Mark D Powell --



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 - 2012, Jelsoft Enterprises Ltd.