T-SQL script for list of SQL Server 2008 R2 databases and user privileges

1152330 pts.
Tags:
SQL Server 2008 R2
T-SQL
Does anyone know if there's a T-SQL script that would list all of our SQL Server 2008 R2 databases and the roles / privileges for one specific user? Thank you very much.
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

Thanks for coming to ITKE. I searched the web and found a few sites that have the information you requested. Here is a link to one of them: https://gallery.technet.microsoft.com/scriptcenter/Get-logins-databases-816f66b2

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • edwinjhoffer
    it works like charm: 
    SELECT DISTINCT rp.name, 
                    ObjectType = rp.type_desc, 
                    PermissionType = pm.class_desc, 
                    pm.permission_name, 
                    pm.state_desc, 
                    ObjectType = CASE 
                                   WHEN obj.type_desc IS NULL 
                                         OR obj.type_desc = 'SYSTEM_TABLE' THEN 
                                   pm.class_desc 
                                   ELSE obj.type_desc 
                                 END, 
                    s.Name as SchemaName,
                    [ObjectName] = Isnull(ss.name, Object_name(pm.major_id)) 
    FROM   sys.database_principals rp 
           INNER JOIN sys.database_permissions pm 
                   ON pm.grantee_principal_id = rp.principal_id 
           LEFT JOIN sys.schemas ss 
                  ON pm.major_id = ss.schema_id 
           LEFT JOIN sys.objects obj 
                  ON pm.[major_id] = obj.[object_id] 
           LEFT JOIN sys.schemas s
                  ON s.schema_id = obj.schema_id
    WHERE  rp.type_desc = 'DATABASE_ROLE' 
           AND pm.class_desc <> 'DATABASE' 
    ORDER  BY rp.name, 
              rp.type_desc, 
              pm.class_desc 
    
    3,740 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: