Tuesday, March 20, 2012

Query to obtain users and privileges from databases

Hi to all, is my first post, i need a query or script to obtain all users and privileges from all my databases, someone to help me. I'm learning Administration SQL server 2005.

I know that sys.database_principals and sys.server_principals have information about that, but i need users - privileges of every database.

thank you

There are a couple of views that can help you here.

sys.server_permissions and sys.database_permissions will show what permissions are granted to logins and users respectively.

Do you need to only check for individual users or do you need to check for roles as well?

thx,

-steven

|||

The following solution provides a way to query all the permissions of all users in the current database. So it is not a complete answer to your question. In order to navigate in every database, it is easier to write managed code program to do that.

Select sys.database_principals.name, permission_name,state, state_desc

from sys.database_permissions, sys.database_principals

where grantee_principal_id = principal_id

|||Thank you very much for your answers

No comments:

Post a Comment