Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

DATABASE_PRINCIPAL_ID (Transact-SQL)

Returns the ID number of a principal in the current database. For more information about principals, see Principals.

Topic link icon Transact-SQL Syntax Conventions


DATABASE_PRINCIPAL_ID ( principal_name )
principal_name

Is an expression of type sysname that represents the principal.

When principal_name is omitted, the ID of the current user is returned. The parentheses are required.

int

NULL on error

DATABASE_PRINCIPAL_ID can be used in a select list, a WHERE clause, or anywhere an expression is allowed. For more information, see Expressions (Transact-SQL).

A. Retrieving the ID of the current user

The following example returns the database principal ID of the current user.

SELECT DATABASE_PRINCIPAL_ID();
GO

B. Retrieving the ID of a specified database principal

The following example returns the database principal ID for the database role db_owner.

SELECT DATABASE_PRINCIPAL_ID('db_owner');
GO

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.