| title | sp_grantlogin (Transact-SQL) | ||
|---|---|---|---|
| description | sp_grantlogin creates a SQL Server login. | ||
| author | VanMSFT | ||
| ms.author | vanto | ||
| ms.reviewer | randolphwest | ||
| ms.date | 06/23/2025 | ||
| ms.service | sql | ||
| ms.subservice | system-objects | ||
| ms.topic | reference | ||
| f1_keywords |
|
||
| helpviewer_keywords |
|
||
| dev_langs |
|
[!INCLUDE SQL Server]
Creates a [!INCLUDE ssNoVersion] login.
Important
[!INCLUDE ssNoteDepFutureAvoid] Use CREATE LOGIN instead.
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions
sp_grantlogin [ @loginame = ] N'loginame'
[ ; ]
The name of a Windows user or group. @loginame is sysname, with no default. The Windows user or group must be qualified with a Windows domain name in the form <domain>\<user>; for example, London\Joeb.
0 (success) or 1 (failure).
sp_grantlogin calls CREATE LOGIN, which supports extra options. For information on creating SQL Server logins, see CREATE LOGIN
sp_grantlogin can't be executed within a user-defined transaction.
Requires membership in the securityadmin fixed server role.
The following example uses CREATE LOGIN to create a [!INCLUDE ssNoVersion] login for the Windows user Corporate\BobJ, which is the preferred method.
CREATE LOGIN [Corporate\BobJ] FROM WINDOWS;
GO