| title | DATABASE_PRINCIPAL_ID (Transact-SQL) | Microsoft Docs | ||||
|---|---|---|---|---|---|
| ms.custom | |||||
| ms.date | 07/29/2017 | ||||
| ms.prod | sql | ||||
| ms.prod_service | database-engine, sql-database | ||||
| ms.service | |||||
| ms.component | t-sql|functions | ||||
| ms.reviewer | |||||
| ms.suite | sql | ||||
| ms.technology |
|
||||
| ms.tgt_pltfrm | |||||
| ms.topic | language-reference | ||||
| f1_keywords |
|
||||
| dev_langs |
|
||||
| helpviewer_keywords |
|
||||
| ms.assetid | 908c7dd8-c10b-4658-92f6-0224f9835dd9 | ||||
| caps.latest.revision | 28 | ||||
| author | edmacauley | ||||
| ms.author | edmaca | ||||
| manager | craigg | ||||
| ms.workload | Inactive |
[!INCLUDEtsql-appliesto-ss2008-asdb-xxxx-xxx-md]
Returns the ID number of a principal in the current database. For more information about principals, see Principals (Database Engine).
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 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 Principals (Database Engine)
Permissions Hierarchy (Database Engine)
sys.database_principals (Transact-SQL)