HAS_DBACCESS
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
HAS_DBACCESS ( 'database_name' )
Work example
Check whether the current login can access a named database.
Test under the intended execution context. Use GRANT and DENY rather than returned identity text.
Check your work A true result does not prove permission on every object inside that database.
Open Microsoft Learn for full syntax, permissions, and details for your version.