Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TSQL to know database role members

I am using SQL 2000 and SQL 2005.

I want to know which logins have db_owner or db_accessadmin rights to which databases.

I can click on users or database roles in every database to see that. Could this be done in an easier way using TSQL?

Thanks in advance

like image 265
Manjot Avatar asked Jan 27 '10 20:01

Manjot


People also ask

How do you check what roles are assigned to a user in SQL?

To find all the role assignments to users in SQL Server database, you can use the following query. SELECT r.name role_principal_name, m.name AS member_principal_name FROM sys. database_role_members rm JOIN sys. database_principals r ON rm.

How can I get a list of all database users?

We can use the following query to see the list of all user in the database server: mysql> Select user from mysql.

How do I find server roles in SQL Server?

To view all server role membership requires the VIEW ANY DEFINITION permission or membership in the securityadmin fixed server role. Logins can also view role memberships of roles they own. In Azure SQL Database, members of the server-role ##MS_DefinitionReader## can query all catalog views.


1 Answers

For SQL 2000 and still works for SQL 2005 too

SELECT
    USER_NAME(memberuid), USER_NAME(groupuid)
FROM
    sys.sysmembers
WHERE
    USER_NAME(groupuid) IN ('db_owner', 'db_accessadmin')
like image 140
gbn Avatar answered Sep 26 '22 10:09

gbn