Skip to content

Latest commit

 

History

History
77 lines (59 loc) · 2.51 KB

has-dbaccess-transact-sql.md

File metadata and controls

77 lines (59 loc) · 2.51 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic f1_keywords helpviewer_keywords dev_langs monikerRange
HAS_DBACCESS (Transact-SQL)
HAS_DBACCESS (Transact-SQL)
VanMSFT
vanto
10/23/2017
sql
t-sql
reference
HAS_DBACCESS_TSQL
HAS_DBACCESS
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
TSQL
>= aps-pdw-2016 || = azure-sqldw-latest || >= sql-server-2016 || >= sql-server-linux-2017 || = azuresqldb-mi-current

HAS_DBACCESS (Transact-SQL)

[!INCLUDE sql-asdbmi-asa-pdw]

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

:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: 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 [!INCLUDE sssampledbobject-md] database.

SELECT HAS_DBACCESS('AdventureWorks2022');  
GO  

Examples: [!INCLUDEssazuresynapse-md] 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)