| title | DATABASE_PRINCIPAL_ID (Transact-SQL) | ||||
|---|---|---|---|---|---|
| description | DATABASE_PRINCIPAL_ID (Transact-SQL) | ||||
| author | VanMSFT | ||||
| ms.author | vanto | ||||
| ms.date | 05/14/2019 | ||||
| ms.service | sql | ||||
| ms.subservice | t-sql | ||||
| ms.topic | reference | ||||
| ms.custom |
|
||||
| f1_keywords |
|
||||
| helpviewer_keywords |
|
||||
| dev_langs |
|
||||
| monikerRange | =azuresqldb-current || =azuresqldb-mi-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqledge-current || =azure-sqldw-latest || =fabric-sqldb |
[!INCLUDE sql-asdb-asdbmi-asa-pdw-fabricsqldb]
This function returns the ID number of a principal in the current database. See Principals (Database Engine) for more information about principals.
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions
DATABASE_PRINCIPAL_ID ( 'principal_name' )
principal_name
An expression of type sysname, that represents the principal. When principal_name is omitted, DATABASE_PRINCIPAL_ID returns the ID of the current user. DATABASE_PRINCIPAL_ID requires the parentheses.
int
NULL if the database principal does not exist.
Use DATABASE_PRINCIPAL_ID in a select list, a WHERE clause, or any place that allows an expression. See Expressions (Transact-SQL) for more information.
This example returns the database principal ID of the current user.
SELECT DATABASE_PRINCIPAL_ID();
GO This example returns the database principal ID for the database role db_owner.
SELECT DATABASE_PRINCIPAL_ID('db_owner');
GO Principals (Database Engine)
Permissions Hierarchy (Database Engine)
sys.database_principals (Transact-SQL)