Skip to content

Latest commit

 

History

History
73 lines (51 loc) · 2.56 KB

sp-revokedbaccess-transact-sql.md

File metadata and controls

73 lines (51 loc) · 2.56 KB
title description author ms.author ms.reviewer ms.date ms.service ms.subservice ms.topic f1_keywords helpviewer_keywords dev_langs
sp_revokedbaccess (Transact-SQL)
sp_revokedbaccess removes a database user from the current database.
VanMSFT
vanto
randolphwest
08/22/2024
sql
system-objects
reference
sp_revokedbaccess_TSQL
sp_revokedbaccess
sp_revokedbaccess
TSQL

sp_revokedbaccess (Transact-SQL)

[!INCLUDE SQL Server]

Removes a database user from the current database.

Important

[!INCLUDE ssNoteDepFutureAvoid] Use DROP USER instead.

:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions

Syntax

sp_revokedbaccess [ @name_in_db = ] N'name_in_db'
[ ; ]

Arguments

[ @name_in_db = ] N'name_in_db'

The name of the database user to be removed. @name_in_db is sysname, with no default. @name_in_db can be the name of a server login, a Windows login, or a Windows group, and must exist in the current database. When you specify a Windows login or Windows group, specify the name by which it's known in the database.

Return code values

0 (success) or 1 (failure).

Remarks

When the database user is removed, the permissions and aliases that depend on the user are also removed.

sp_revokedbaccess can remove only database users from the current database. Before removing a database user that owns objects in the current database, you must either transfer ownership of the objects or drop them from the database. For more information, see ALTER AUTHORIZATION.

sp_revokedbaccess can't be executed within a user-defined transaction.

Permissions

Requires ALTER ANY USER permission on the database.

Examples

The following example removes the database user mapped to Edmonds\LolanSo from the current database.

EXEC sp_revokedbaccess 'Edmonds\LolanSo';
GO

Related content