In this post explains how to use the SQL Server ALTER LOGIN statement with syntax and examples.
The ALTER LOGIN statement modifies an identity used to connect to a SQL Server instance. You can use the ALTER LOGIN statement to change a password, force a password change, disable a login, enable a login, unlock a login, rename a login, etc.
The syntax for the ALTER LOGIN statement in SQL Server is:
The Login name currently assigned to the Login.
Enables the Login.
Disables the Login.
The new password to assign to the Login that is authenticated using SQL Server authentication.
The hashed value of the password to assign to the Login using SQL Server authentication.
The old password using SQL Server authentication.
It is used when you want to force the password to be changed the first time that the Login is used after the ALTER LOGIN statement.
It will unlock a Login that has been locked out.
The default database to assign to the Login.
The default language to assign to the Login.
The new name of the Login if you are using the ALTER LOGIN statement to rename a Login.
By default, it is set to OFF. This option determines whether password expiration policy is enforced. You must specifiy CHECK_EXPIRATION = ON when you use the MUST_CHANGE option.
The name of a credential to assign to the Login.
Removes any mapped credentials from the Login.
Adds a credential to the Login.
Removes a credential from the Login.
Let's look at how to change a password using the ALTER LOGIN statement in SQL Server (Transact-SQL).
For example:
This ALTER LOGIN example would alter the Login called AODBA and change the password of this login to 'bestsite'.
Let's look at how to change a password and force the password to be changed after the first login using the ALTER LOGIN statement in SQL Server (Transact-SQL).
For example:
This ALTER LOGIN example would alter the Login called AODBA and change the password of this login to 'bestsite'. But because we have specified the MUST CHANGE option and set the CHECK_EXPIRATION to ON, the password will have to be changed again in SQL Server after the first login (following the ALTER LOGIN statement). So in effect, it is like resetting a password to a temporary password for a Login.
Next, let's look at how to disable a Login using the ALTER LOGIN statement in SQL Server (Transact-SQL).
For example:
This ALTER LOGIN example would disable the Login called AODBA.
Next, let's look at how to enable a Login using the ALTER LOGIN statement in SQL Server (Transact-SQL).
For example:
This ALTER LOGIN example would enable the Login called AODBA.
Next, let's look at how to unlock a Login using the ALTER LOGIN statement in SQL Server (Transact-SQL).
For example:
This ALTER LOGIN example would unlock the Login called AODBA and set the password to 'bestsite'.
Finally, let's look at how to rename a Login using the ALTER LOGIN statement in SQL Server (Transact-SQL).
For example:
This ALTER LOGIN example would rename the Login called AODBA to checkyoursite.