Skip to content

Latest commit

 

History

History
70 lines (49 loc) · 2.17 KB

File metadata and controls

70 lines (49 loc) · 2.17 KB
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
sp_grantlogin_TSQL
sp_grantlogin
helpviewer_keywords
sp_grantlogin
dev_langs
TSQL

sp_grantlogin (Transact-SQL)

[!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

Syntax

sp_grantlogin [ @loginame = ] N'loginame'
[ ; ]

Arguments

[ @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.

Return code values

0 (success) or 1 (failure).

Remarks

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.

Permissions

Requires membership in the securityadmin fixed server role.

Examples

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

Related content