sp_grantlogin (Transact-SQL)sp_grantlogin (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 登录名。Creates a SQL ServerSQL Server login.

重要

此功能处于维护模式并且可能会在 Microsoft SQL Server 将来的版本中被删除。This feature is in maintenance mode and may be removed in a future version of Microsoft SQL Server. 请避免在新的开发工作中使用该功能,并着手修改当前还在使用该功能的应用程序。Avoid using this feature in new development work, and plan to modify applications that currently use this feature. 使用CREATE LOGIN相反。Use CREATE LOGIN instead.

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

语法Syntax

sp_grantlogin [@loginame=] 'login'  

参数Arguments

[ @loginame = ] 'login' 是 Windows 用户或组的名称。[ @loginame = ] 'login' Is the name of a Windows user or group. 必须使用窗体中的 Windows 域名限定 Windows 用户或组\用户; 例如, London\JoebThe Windows user or group must be qualified with a Windows domain name in the form Domain\User; for example, London\Joeb. 登录名sysname ,无默认值。login is sysname, with no default.

返回代码值Return Code Values

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

备注Remarks

sp_grantlogin调用 CREATE LOGIN,后者支持其他选项。sp_grantlogin calls CREATE LOGIN, which supports additional options. 有关创建 SQL Server 登录名的信息,请参阅创建登录名(TRANSACT-SQL)For information on creating SQL Server logins, see CREATE LOGIN (Transact-SQL)

sp_grantlogin不能在用户定义的事务内执行。sp_grantlogin cannot be executed within a user-defined transaction.

权限Permissions

要求对服务器拥有 ALTER ANY LOGIN 权限。Requires ALTER ANY LOGIN permission on the server.

示例Examples

下面的示例使用CREATE LOGIN来创建SQL ServerSQL ServerWindows 用户的登录名Corporate\BobJ.这是首选的方法。The following example uses CREATE LOGIN to create a SQL ServerSQL Server login for the Windows user Corporate\BobJ. This is the preferred method.

CREATE LOGIN [Corporate\BobJ] FROM WINDOWS;  
GO  

请参阅See Also

安全存储过程 (Transact-SQL) Security Stored Procedures (Transact-SQL)
CREATE LOGIN (Transact-SQL) CREATE LOGIN (Transact-SQL)
系统存储过程 (Transact-SQL)System Stored Procedures (Transact-SQL)