HAS_DBACCESS (Transact-SQL)

HAS_DBACCESS (Transact-SQL)

 

THIS TOPIC APPLIES TO:yesSQL Server (starting with 2008) noAzure SQL Database yesAzure SQL Data Warehouse yesParallel Data Warehouse

Returns information about whether the user has access to the specified database.

Topic link icon Transact-SQL Syntax Conventions


HAS_DBACCESS ( 'database_name' )
-- Azure SQL Data Warehouse and Parallel Data Warehouse
HAS_DBACCESS ('database_name')

'database_name' 

The name of the database for which the user wants access information. database_name is sysname.

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.

Requires membership in the public role.

The following example tests whether current user has access to the AdventureWorks2012 database.

SELECT HAS_DBACCESS('AdventureWorks2012');
GO

The following example tests whether current user has access to the AdventureWorksPDW2012 database.

SELECT HAS_DBACCESS('AdventureWorksPDW2012');
GO

Community Additions

ADD
Show:
© 2016 Microsoft