THIS TOPIC APPLIES TO: SQL Server Azure SQL Database Azure SQL Data Warehouse Parallel Data Warehouse
Returns the ID number of a principal in the current database. For more information about principals, see Principals (Database Engine).
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).
The following example returns the database principal ID of the current user.
SELECT DATABASE_PRINCIPAL_ID(); GO
The following example returns the database principal ID for the database role db_owner.
SELECT DATABASE_PRINCIPAL_ID('db_owner'); GO