| title | sp_password (Transact-SQL) | ||
|---|---|---|---|
| description | sp_password adds or changes a password for 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]
Adds or changes a password for a [!INCLUDE ssNoVersion] login.
Important
[!INCLUDE ssNoteDepFutureAvoid] Use ALTER LOGIN instead.
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions
sp_password
[ [ @old = ] N'old' ]
, [ @new = ] N'new'
[ , [ @loginame = ] N'loginame' ]
[ ; ]
The old password. @old is sysname, with a default of NULL.
The new password. @new is sysname, with no default. @old must be specified if named parameters aren't used.
Important
Don't use a NULL password. Use a strong password. For more information, see Strong Passwords.
The name of the login affected by the password change. @loginame is sysname, with a default of NULL. @loginame must already exist and can be specified only by members of the sysadmin or securityadmin fixed server roles.
0 (success) or 1 (failure).
sp_password calls ALTER LOGIN. This statement supports more options. For information on changing passwords, see ALTER LOGIN.
sp_password can't be executed within a user-defined transaction.
Requires ALTER ANY LOGIN permission. Also requires CONTROL SERVER permission to reset a password without supplying the old password, or if the login that is being changed has CONTROL SERVER permission.
A principal can change its own password.
The following example shows how to use ALTER LOGIN to change the password for the login Victoria to <password>. This method is preferred. The user that is executing this command must have CONTROL SERVER permission.
ALTER LOGIN Victoria WITH PASSWORD = '<password>';
GOThe following example shows how to use ALTER LOGIN to change the password for the login Victoria from <password> to <new-password>. This method is preferred. User Victoria can execute this command without extra permissions. Other users require ALTER ANY LOGIN permission.
Replace <new-password> and <password> with strong passwords.
ALTER LOGIN Victoria WITH PASSWORD = '<new-password>' OLD_PASSWORD = '<password>';
GO