--- title: "sp_grantlogin (Transact-SQL) | Microsoft Docs" ms.custom: "" ms.date: "03/14/2017" ms.prod: sql ms.prod_service: "database-engine" ms.reviewer: "" ms.technology: system-objects ms.topic: "language-reference" f1_keywords: - "sp_grantlogin_TSQL" - "sp_grantlogin" dev_langs: - "TSQL" helpviewer_keywords: - "sp_grantlogin" ms.assetid: 0c873d99-c3bf-4eb1-948b-a46cb235ccd4 ms.author: vanto author: VanMSFT --- # sp_grantlogin (Transact-SQL) [!INCLUDE[tsql-appliesto-ss2008-xxxx-xxxx-xxx-md](../../includes/tsql-appliesto-ss2008-xxxx-xxxx-xxx-md.md)] Creates a [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] login. > [!IMPORTANT] > [!INCLUDE[ssNoteDepFutureAvoid](../../includes/ssnotedepfutureavoid-md.md)] Use [CREATE LOGIN](../../t-sql/statements/create-login-transact-sql.md) instead. ![Topic link icon](../../database-engine/configure-windows/media/topic-link.gif "Topic link icon") [Transact-SQL Syntax Conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md) ## Syntax ``` sp_grantlogin [@loginame=] 'login' ``` ## Arguments `[ @loginame = ] 'login'` Is the name of a Windows user or group. The Windows user or group must be qualified with a Windows domain name in the form *Domain*\\*User*; for example, **London\Joeb**. *login* is **sysname**, with no default. ## Return Code Values 0 (success) or 1 (failure) ## Remarks **sp_grantlogin** calls CREATE LOGIN, which supports additional options. For information on creating SQL Server logins, see [CREATE LOGIN (Transact-SQL)](../../t-sql/statements/create-login-transact-sql.md) **sp_grantlogin** cannot be executed within a user-defined transaction. ## Permissions Requires ALTER ANY LOGIN permission on the server. ## Examples The following example uses `CREATE LOGIN` to create a [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] login for the Windows user `Corporate\BobJ.` This is the preferred method. ```sql CREATE LOGIN [Corporate\BobJ] FROM WINDOWS; GO ``` ## See Also [Security Stored Procedures (Transact-SQL)](../../relational-databases/system-stored-procedures/security-stored-procedures-transact-sql.md) [CREATE LOGIN (Transact-SQL)](../../t-sql/statements/create-login-transact-sql.md) [System Stored Procedures (Transact-SQL)](../../relational-databases/system-stored-procedures/system-stored-procedures-transact-sql.md)