Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All


Applies To: SQL Server 2014, SQL Server 2016 Preview

Topic Status: Some information in this topic is preview and subject to change in future releases. Preview information describes new features or changes to existing features in Microsoft SQL Server 2016 Community Technology Preview 2 (CTP2).

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

Applies to: SQL Server (SQL Server 2008 through current version), Azure SQL Database.

Topic link icon Transact-SQL Syntax Conventions

DATABASE_PRINCIPAL_ID ( '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.


NULL when the database principal does not exist

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.


B. Retrieving the ID of a specified database principal

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


Community Additions

© 2015 Microsoft