Events
Sep 15, 6 AM - Sep 17, 3 PM
The best SQL community-led learning event. Sept 2025. Save €200 with code FABLEARN.
Get registeredThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to:
SQL Server
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
This function returns the ID number of a principal in the current database. See Principals (Database Engine) for more information about principals.
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)
Events
Sep 15, 6 AM - Sep 17, 3 PM
The best SQL community-led learning event. Sept 2025. Save €200 with code FABLEARN.
Get registered