Skip to content

Latest commit

 

History

History
80 lines (62 loc) · 2.68 KB

File metadata and controls

80 lines (62 loc) · 2.68 KB
title HAS_DBACCESS (Transact-SQL) | Microsoft Docs
ms.custom
ms.date 10/23/2017
ms.prod sql
ms.prod_service sql-data-warehouse, pdw, sql-database
ms.reviewer
ms.technology t-sql
ms.topic language-reference
f1_keywords
HAS_DBACCESS_TSQL
HAS_DBACCESS
dev_langs
TSQL
helpviewer_keywords
permissions [SQL Server], verifying
permissions [SQL Server], user access status
HAS_DBACCESS
checking permission status
verifying permission status
users [SQL Server], access rights status
testing permissions
status information [SQL Server], user access
ms.assetid 99b43a72-0722-4a7b-a493-bdee1c74c7b9
author VanMSFT
ms.author vanto
monikerRange >=aps-pdw-2016||=azure-sqldw-latest||>=sql-server-2016||=sqlallproducts-allversions||>=sql-server-linux-2017||=azuresqldb-mi-current

HAS_DBACCESS (Transact-SQL)

[!INCLUDEtsql-appliesto-ss2008-xxxx-asdw-pdw-md]

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

Topic link icon Transact-SQL Syntax Conventions

Syntax

HAS_DBACCESS ( 'database_name' )  

Arguments

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

Return Types

int

Remarks

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.

Permissions

Requires membership in the public role.

Examples

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

SELECT HAS_DBACCESS('AdventureWorks2012');  
GO  

Examples: [!INCLUDEssSDWfull] and [!INCLUDEssPDW]

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

SELECT HAS_DBACCESS('AdventureWorksPDW2012');  
GO  

See Also

IS_MEMBER (Transact-SQL)
IS_SRVROLEMEMBER (Transact-SQL)