SQL Flow Field Guide

USER_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

Syntax at a glance

USER_ID ( [ 'user' ] )

Work example

Resolve a database user name to its database-local principal id.

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

Check your work Use it only in the current database and handle null for missing or invisible users.

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