HAS_DBACCESS()

How to know to which database you have access?. For this question there is a function HAS_DBACCESS returns 1 if the user has access to the database, otherwise, it will return as 0. If you see value NULL, that means the database name passed to the function is invalid.


SELECT name AS DatabaseName,
HAS_DBACCESS(name) AS HasDBAccess
FROM sys.databases WHERE HAS_DBACCESS(name) = 1