Applies To: SQL Server 2014, SQL Server 2016 Preview
Topic Status: Some information in this topic is preview and subject to change in future releases. Preview information describes new features or changes to existing features in Microsoft SQL Server 2016 Community Technology Preview 2 (CTP2).
Returns information about whether the user has access to the specified database.
Applies to: SQL Server (SQL Server 2008 through current version) , Azure SQL Data Warehouse Public Preview.
HAS_DBACCESS returns 1 if the user has access to the database, 0 if the user has no access to the database, and NULL if the database name is not valid.
HAS_DBACCESS returns 0 if the database is offline or suspect.
HAS_DBACCESS returns 0 if the database is in single-user mode and the database is in use by another user.
The following example tests whether current user has access to the AdventureWorks2012 database.
SELECT HAS_DBACCESS('AdventureWorks2012'); GO