Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to:
Analytics Platform System (PDW)
Changes the properties of a SQL Server login account.
Note
Microsoft Entra ID was previously known as Azure Active Directory (Azure AD).
Transact-SQL syntax conventions
Syntax
ALTER LOGIN login_name
{
<status_option>
| WITH <set_option> [ , ... ]
}
<status_option> ::= ENABLE | DISABLE
<set_option> ::=
PASSWORD = 'password'
[
OLD_PASSWORD = 'oldpassword'
| <password_option> [ <password_option> ]
]
| NAME = login_name
| CHECK_POLICY = { ON | OFF }
| CHECK_EXPIRATION = { ON | OFF }
<password_option> ::=
MUST_CHANGE | UNLOCK
Arguments
login_name
Specifies the name of the SQL Server login that is being changed. Domain logins must be enclosed in brackets in the format [domain\user].
ENABLE | DISABLE
Enables or disables this login. Disabling a login doesn't affect the behavior of logins that are already connected. (Use the KILL statement to terminate an existing connection.) Disabled logins retain their permissions and can still be impersonated.
PASSWORD = 'password'
Applies only to SQL Server logins. Specifies the password for the login that is being changed. Passwords are case-sensitive.
Important
When a login (or a contained database user) connects and is authenticated, the connection caches identity information about the login. For a Windows Authentication login, this includes information about membership in Windows groups. The identity of the login remains authenticated as long as the connection is maintained. To force changes in the identity, such as a password reset or change in Windows group membership, the login must sign out from the authentication authority (Windows or SQL Server), and sign in again. A member of the sysadmin fixed server role or any login with the ALTER ANY CONNECTION permission can use the KILL command to end a connection and force a login to reconnect. SQL Server Management Studio (SSMS) can reuse connection information when opening multiple connections to Object Explorer and Query Editor windows. Close all connections to force reconnection.
OLD_PASSWORD = 'old_password'
Applies only to SQL Server logins. The current password of the login to which a new password will be assigned. Passwords are case-sensitive.
MUST_CHANGE
Applies only to SQL Server logins. If this option is included, SQL Server prompts for an updated password the first time the altered login is used.
NAME = login_name
The new name of the login that is being renamed. If the login is a Windows login, the SID of the Windows principal corresponding to the new name must match the SID associated with the login in SQL Server. The new name of a SQL Server login can't contain a backslash character (\).
CHECK_EXPIRATION = { ON | OFF }
Applies only to SQL Server logins. Specifies whether password expiration policy should be enforced on this login. The default value is OFF.
CHECK_POLICY = { ON | OFF }
Applies only to SQL Server logins. Specifies that the Windows password policies of the computer on which SQL Server is running should be enforced on this login. The default value is ON.
UNLOCK
Applies only to SQL Server logins. Specifies that a login that is locked out should be unlocked.
Remarks
When CHECK_POLICY is set to ON, the HASHED argument can't be used.
When CHECK_POLICY is changed to ON, the following behavior occurs:
- The password history is initialized with the value of the current password hash.
When CHECK_POLICY is changed to OFF, the following behavior occurs:
- CHECK_EXPIRATION is also set to OFF.
- The password history is cleared.
- The value of lockout_time is reset.
If MUST_CHANGE is specified, CHECK_EXPIRATION and CHECK_POLICY must be set to ON. Otherwise, the statement fails.
If CHECK_POLICY is set to OFF, CHECK_EXPIRATION can't be set to ON. An ALTER LOGIN statement that has this combination of options fail.
You can't use ALTER_LOGIN with the DISABLE argument to deny access to a Windows group. This is by design. For example, ALTER_LOGIN [domain\group] DISABLE returns the following error message:
"Msg 15151, Level 16, State 1, Line 1 "Cannot alter the login '*Domain\Group*', because it doesn't exist or you don't have permission."
In SQL Database, login data required to authenticate a connection and server-level firewall rules are temporarily cached in each database. This cache is periodically refreshed. To force a refresh of the authentication cache and make sure that a database has the latest version of the logins table, execute DBCC FLUSHAUTHCACHE.
Permissions
Requires ALTER ANY LOGIN permission.
If the CREDENTIAL option is used, also requires ALTER ANY CREDENTIAL permission.
If the login that is being changed is a member of the sysadmin fixed server role or a grantee of CONTROL SERVER permission, also requires CONTROL SERVER permission when making the following changes:
- Resetting the password without supplying the old password.
- Enabling MUST_CHANGE, CHECK_POLICY, or CHECK_EXPIRATION.
- Changing the login name.
- Enabling or disabling the login.
- Mapping the login to a different credential.
A principal can change the password, default language, and default database for its own login.
Examples
These examples also include examples for using other SQL products. See which previous arguments are supported.
A. Enable a disabled login
The following example enables the login Mary5.
ALTER LOGIN Mary5 ENABLE;
B. Change the password of a login
The following example changes the password of login Mary5 to a strong password.
ALTER LOGIN Mary5 WITH PASSWORD = '<password>';
C. Change the name of a login
The following example changes the name of login Mary5 to John2.
ALTER LOGIN Mary5 WITH NAME = John2;
D. Map a login to a credential
The following example maps the login John2 to the credential Custodian04.
ALTER LOGIN John2 WITH CREDENTIAL = Custodian04;
E. Map a login to an Extensible Key Management credential
The following example maps the login Mary5 to the EKM credential EKMProvider1.
Applies to: SQL Server.
ALTER LOGIN Mary5 ADD CREDENTIAL EKMProvider1;
GO
F. Unlock a login
To unlock a SQL Server login, execute the following statement, replacing **** with the desired account password.
ALTER LOGIN [Mary5] WITH PASSWORD = '****' UNLOCK;
GO
To unlock a login without changing the password, turn off the check policy and then on again.
ALTER LOGIN [Mary5] WITH CHECK_POLICY = OFF;
ALTER LOGIN [Mary5] WITH CHECK_POLICY = ON;
GO
G. Change the password of a login using HASHED
The following example changes the password of the TestUser login to an already hashed value.
Applies to: SQL Server.
ALTER LOGIN TestUser WITH PASSWORD = 0x01000CF35567C60BFB41EBDE4CF700A985A13D773D6B45B90900 HASHED;
GO