USER_ID (TSQL Function)

Returns the ID of the specified user or role in the current database.

This function will be obsoleted. You should use DATABASE_PRINCIPAL_ID, which returns the same result.

Syntax

USER_ID ( ['principal_name'] )

Arguments

principal_name
optional argument, name of a user or role, of type varchar. If omitted, the ID of the current user in the current database is returned.

Return Types

Returns bigint.

Remarks

Returns NULL if the user or role doesn’t exist in the current database.

Examples

DECLARE @u VARCHAR(30) = 'fred';
DECLARE @a BIGINT;

SET @a = USER_ID(@u);
PRINT @a;
PRINT USER_NAME(@a);

The result is:

30104
fred