SQL Flow Field Guide

DATABASE_PRINCIPAL_ID

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

security context lookup

What changes

Input
security context (login, user, roles, permissions)
Output or change
name, id or boolean
Return type
int NULL if the database principal does not exist.

Syntax at a glance

DATABASE_PRINCIPAL_ID ( 'principal_name' )

Work example

Resolve a database principal name to its database-local identifier.

Test under the intended execution context. Use GRANT and DENY rather than returned identity text.

Check your work Check null and avoid using the identifier outside its database.

Open Microsoft Learn for full syntax, permissions, and details for your version.