Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register today