473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

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 --

Apr 25 '07 #1
2 4845
Mark D Powell (Ma*********@eds.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, es****@sommarskog.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
Apr 25 '07 #2
On Apr 25, 5:46 pm, Erland Sommarskog <esq...@sommarskog.sewrote:
Mark D Powell (Mark.Pow...@eds.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...@sommarskog.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 --

Apr 26 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tom Dauria | last post by:
I have a SQL database with an Access front end. In the database I have a read only and a read write role. When a read only user opens the database I want all the fields on the form to be locked...
3
by: teddysnips | last post by:
Currently studying for 70-229. I'm trying to understand how security for users is managed in SQL Server. I've been using SQL Server for a few years now, but without investigating the bits that...
1
by: New MSSQL DBA | last post by:
hi, can anyone help me out with this report. I need to produce a report for the database level user permission. like for a database: DB_A, I want to output as such: .... other public G ...
1
by: rcamarda | last post by:
I wish to create a user that can backup any or all databases in our SQL Server 2000 Instance. I thought there would be a server role for this function, however I can only find that after I grant...
2
by: Len Kowalik | last post by:
MSAccess 2000, SQL-Server 97 I am getting a permission denied response from an attempt to execute a stored proc, which has public access revoked and app role access, on the last statement of the...
1
by: WhiskyRomeo | last post by:
I have an ASP.NET application that was ported from a server where IIS, the database (SQL Server 2000) and web application were on the same server. The new server is a Windows 2003 (Webserver...
1
by: MADS | last post by:
Hi everybody, I've five instances of SQL Server 2000 with the SAME database with a DIFFERENT owner in each server. I, as the administrator, have a lot of queries that I have to execute in some...
1
by: Mark D Powell | last post by:
Using SQL Server 2000 I need to extract all the grants made to a user created role so that I can recreate the role in another version of a database and there are more grants than I want to do by...
2
by: gnewsgroup | last post by:
OK, I know this has been a popular question from newbies. But, please don't haste to reply yet. I've googled and tested for a few hours, and cannot have this problem resolved. I have...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.