DATABASE_PRINCIPAL_ID (TSQL Function)
Returns the ID of the specified user or role in the current database.
It returns the same result as USER_ID
, which will be obsoleted.
Syntax
DATABASE_PRINCIPAL_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 = DATABASE_PRINCIPAL_ID(@u);
PRINT @a;
PRINT USER_NAME(@a);
The result is:
30104
fred