SUSER_ID (Transact-SQL)

Applies to: SQL Server Azure SQL Managed Instance

Returns the login identification number of the user.

Note

Starting with SQL Server 2005 (9.x), SUSER_ID returns the value listed as principal_id in the sys.server_principals catalog view.

Transact-SQL syntax conventions

Syntax

SUSER_ID ( [ 'login' ] )   

Arguments

' login '
Is the login name of the user. login is nchar. If login is specified as char, login is implicitly converted to nchar. login can be any SQL Server login or Windows user or group that has permission to connect to an instance of SQL Server. If login is not specified, the login identification number for the current user is returned. If the parameter contains the word NULL will return NULL.

Return Types

int

Remarks

SUSER_ID returns an identification number only for logins that have been explicitly provisioned inside SQL Server. This ID is used within SQL Server to track ownership and permissions. This ID is not equivalent to the SID of the login that is returned by SUSER_SID. If login is a SQL Server login, the SID maps to a GUID. If login is a Windows login or Windows group, the SID maps to a Windows security identifier.

SUSER_SID returns a SUID only for a login that has an entry in the syslogins system table.

System functions can be used in the select list, in the WHERE clause, and anywhere an expression is allowed, and must always be followed by parentheses, even if no parameter is specified.

Examples

The following example returns the login identification number for the sa login.

SELECT SUSER_ID('sa');  

See Also

sys.server_principals (Transact-SQL)
SUSER_SID (Transact-SQL)
System Functions (Transact-SQL)