Table of Contents
MS SQL Server: ALTER LOGIN Command in SQL Server is easier to understand when the core ideas are paired with practical examples. The sections below explain the topic clearly, highlight useful steps, and point out details that can prevent common errors.
The ALTER LOGIN command helps modify the identity used to connect to SQL Server. You can use this command to change your password, it is required to change your password, disable, reactivate, unlock, rename your login.
Syntax of ALTER LOGIN
ALTER LOGIN ten_dangnhap{ ENABLE | DISABLE| WITH PASSWORD = 'matkhau' | matkhau_bam HASHED[ OLD_PASSWORD = 'matkhau_cu' ]| MUST_CHANGE| UNLOCK| DEFAULT_DATABASE = ten_cosodulieu| DEFAULT_LANGUAGE = ten_ngonngu| NAME = ten_dangnhap_moi| CHECK_EXPIRATION = { ON | OFF }| CHECK_POLICY = { ON | OFF }| CREDENTIAL = ten_chungthuc| NO CREDENTIAL| ADD CREDENTIAL ten_chungthuc_moi| DROP CREDE| DROP CREDENTIAL ten_chungthuc};
Variable name or variable value
Username
Name of the login account.
ENABLE
Activate the login account.
DISABLE
Disable login account.
matkhau
New password is used for login account, authenticated by SQL Server Authentication.
matkhau_bam
The hash function value of the login password, authenticated by SQL Server Authentication.
matkhau_cu
Old password authenticated by SQL Server Authentication.
MUST_CHANGE
Used when forcing the password to change after the first login, is used after the ALTER LOGIN command.
UNLOCK
Unlock locked login account
ten_cosodulieu
Default database
ten_ngonngu
Default language for login account.
ten_dangnhap_moi
New name of the login account if you use the ALTER LOGIN command to change your username.
CHECK_EXPIRATION
The default is set to OFF. This option determines the password expiration policy. Must set CHECK_EXPIRATION = ON if using MUST_CHANGE.
ten_chungthuc
Authentication name of the login account.
As an example,, change the password
ALTER LOGIN quantrimangWITH PASSWORD = 'congnghe';
This ALTER LOGIN command changes the Login with the name TipsMakeand the password of this login account to congnghe.
As an example,, change the password and must change the password
ALTER LOGIN quantrimangWITH PASSWORD = 'congnghe' MUST_CHANGE,CHECK_EXPIRATION =ON;
As an example,, this ALTER LOGIN command will change the Login named tipsmake, change the password to congnghe. Since selecting MUST_CHANGE and CHECK_EXPIRATION is ON, the password must be changed after logging in for the first time (after the ALTER LOGIN command). This will be like resetting a password to a temporary password.
Disable Login example
ALTER LOGIN TipsMakeDISABLE;
This command will disable the Login named tipsmake.
As an example,, enable Login
ALTER LOGIN TipsMakeENABLE;
This command will activate the login account named quatrimang.
Example Login login
ALTER LOGIN quantrimangWITH PASSWORD = 'congnghe'UNLOCK;
The command in the above example will unlock the login account of TipsMakeand set the password to be congnghe.
FAQ
What is MS SQL Server: ALTER LOGIN Command in SQL Server?
The ALTER LOGIN command helps modify the identity used to connect to SQL Server.
Why is MS SQL Server: ALTER LOGIN Command in SQL Server important?
A clear understanding of MS SQL Server: ALTER LOGIN Command in SQL Server helps you make informed decisions, avoid common mistakes, and use the relevant tools or techniques more effectively.
How should beginners approach MS SQL Server: ALTER LOGIN Command in SQL Server?
Start with the fundamental concepts, follow the examples step by step, and test each change in a safe environment before applying it to important systems or data.
Reader Comments 0
Sign in with email or Google to join the discussion.