sp_validatelogins (Transact-SQL)sp_validatelogins (Transact-SQL)

适用对象:是SQL Server 否Azure SQL 数据库 否Azure Synapse Analytics (SQL DW) 否并行数据仓库 APPLIES TO: yesSQL Server noAzure SQL Database noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

报告有关映射到 SQL ServerSQL Server 主体但不再存在于 Windows 环境中的 Windows 用户和组的信息。Reports information about Windows users and groups that are mapped to SQL ServerSQL Server principals but no longer exist in the Windows environment.

主题链接图标 Transact-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax

  
sp_validatelogins  

返回代码值Return Code Values

0(成功)或 1(失败)0 (success) or 1 (failure)

结果集Result Sets

列名称Column name 数据类型Data type 说明Description
SIDSID varbinary (85)varbinary(85) Windows 用户或组的 Windows 安全性标识符 (SID)。Windows security identifier (SID) of the Windows user or group.
NT LoginNT Login sysnamesysname Windows 用户或组的名称。Name of the Windows user or group.

备注Remarks

如果孤立的服务器级主体拥有数据库用户,则必须在删除孤立的服务器主体之前首先删除该数据库用户。If the orphaned server-level principal owns a database user, the database user must be removed before the orphaned server principal can be removed. 若要删除数据库用户,请使用DROP userTo remove a database user, use DROP USER. 如果服务器级主体在数据库中拥有安全对象,则必须转移安全对象的所有权,或删除这些安全对象。If the server-level principal owns securables in the database, ownership of the securables must be transferred or they must be dropped. 若要转让数据库安全对象的所有权,请使用ALTER AUTHORIZATIONTo transfer ownership of database securables, use ALTER AUTHORIZATION.

若要删除对不再存在的 Windows 用户和组的映射,请使用删除登录名To remove mappings to Windows users and groups that no longer exist, use DROP LOGIN.

权限Permissions

要求具有sysadminsecurityadmin固定服务器角色的成员身份。Requires membership in the sysadmin or securityadmin fixed server role.

示例Examples

以下示例显示不存在但仍被授权访问 SQL ServerSQL Server 实例的 Windows 用户和组。The following example displays the Windows users and groups that no longer exist but are still granted access to an instance of SQL ServerSQL Server.

EXEC sp_validatelogins;  
GO  

另请参阅See Also

系统存储过程 (Transact-SQL) System Stored Procedures (Transact-SQL)
安全存储过程 (Transact-sql) Security Stored Procedures (Transact-SQL)
DROP USER (Transact-sql) DROP USER (Transact-SQL)
DROP LOGIN (Transact-sql) DROP LOGIN (Transact-SQL)
ALTER AUTHORIZATION (Transact-SQL)ALTER AUTHORIZATION (Transact-SQL)