IS_SRVROLEMEMBER

Transact-SQL Reference

Transact-SQL Reference

IS_SRVROLEMEMBER

Indicates whether the current user login is a member of the specified server role.

Syntax

IS_SRVROLEMEMBER ( 'role' [ , 'login' ] )

Arguments

'role'

Is the name of the server role being checked. role is sysname.

Valid values for role are:

  • sysadmin
  • dbcreator

  • diskadmin

  • processadmin

  • serveradmin

  • setupadmin

  • securityadmin

'login'

Is the optional name of the login to check. login is sysname, with a default of NULL. If not specified, the login account for the current user is used.

Return Types

int

Remarks

IS_SRVROLEMEMBER returns these values.

Return value Description
0 login is not a member of role.
1 login is a member of role.
NULL role or login is not valid.

This function can be useful to programmatically detect whether the current user can perform an activity requiring the server role's permissions.

If a Windows NT® user, such as London\JoeB, is specified for login, IS_SRVROLEMEMBER returns NULL if the user has not previously been granted or denied direct access to Microsoft SQL Server using sp_grantlogin or sp_denylogin.

Examples

This example indicates whether the current user is a member of the sysadmin fixed server role.

IF IS_SRVROLEMEMBER ('sysadmin') = 1
   print 'Current user''s login is a member of the sysadmin role'
ELSE IF IS_SRVROLEMEMBER ('sysadmin') = 0
   print 'Current user''s login is NOT a member of the sysadmin role'
ELSE IF IS_SRVROLEMEMBER ('sysadmin') IS NULL
   print 'ERROR: Invalid server role specified'

See Also

IS_MEMBER

Security Functions