Discussion:
how to check if a user is a DBA in SQL Server
(too old to reply)
akhila
2007-06-01 11:44:41 UTC
Permalink
Hi All,

I need information on how to check if a user is a DBA in SQL Server.

In Oracle we can achieve the result by using the following query

ResultSet rs = stmt.executeQuery("select GRANTEE from
DBA_ROLE_PRIVS where " +
"GRANTED_ROLE='DBA' " +
"and GRANTEE='" + userName.toUpperCase() + "'" );
if(rs.next()) {
//user is a DBA
}

How do we find out for SQL Server Database.

Thanks in advance.
John Bell
2007-06-01 12:29:01 UTC
Permalink
Hi
Post by akhila
Hi All,
I need information on how to check if a user is a DBA in SQL Server.
In Oracle we can achieve the result by using the following query
ResultSet rs = stmt.executeQuery("select GRANTEE from
DBA_ROLE_PRIVS where " +
"GRANTED_ROLE='DBA' " +
"and GRANTEE='" + userName.toUpperCase() + "'" );
if(rs.next()) {
//user is a DBA
}
How do we find out for SQL Server Database.
Thanks in advance.
If you want to know if they are in the db_owner role then use the IS_MEMBER
function, if you want to know if they own the database then the SID of the
login can be gained from sysdatabases.

John
Razvan Socol
2007-06-01 12:34:43 UTC
Permalink
Hello, akhila

I think you want something like:

SELECT IS_SRVROLEMEMBER('YourUserName','sysadmin')

Razvan

Continue reading on narkive:
Loading...