Alter login in SQL Server

Alter login statements can be used to changes the properties of a SQL Server login account.

Syntax:

ALTER LOGIN loginname;
GO

Enable a disabled login –

Syntax :

ALTER LOGIN loginname ENABLE;

Example –



ALTER LOGIN geeks ENABLE;

Change password of a login
Syntax :

ALTER LOGIN geeks WITH PASSWORD = 'newpassword';

Example –

ALTER LOGIN geeks WITH PASSWORD = ‘G9h$fm@1LZe’;

Change the password for a login when logged in using the same login

Syntax:

ALTER LOGIN loginname 
WITH PASSWORD = 'newpassword' OLD_PASSWORD = 'oldpassword';

Example –

ALTER LOGIN geeks 
WITH PASSWORD = ‘G9h$fm@1LZe’ OLD_PASSWORD = ‘Ge@@k$s12’;

Change name of a login

Syntax:



ALTER LOGIN loginnmae WITH NAME = newname;

Example –

ALTER LOGIN geeks WITH NAME = geek;

Unlock a login

Syntax:

ALTER LOGIN loginnmae WITH PASSWORD = 'password' UNLOCK ;

Example –

ALTER LOGIN geeks WITH PASSWORD = ‘G9h$fm@1LZe’ UNLOCK ;

Unlock a login without changing the password

Syntax:

ALTER LOGIN [loginname] WITH CHECK_POLICY = OFF;
ALTER LOGIN [loginnmae] WITH CHECK_POLICY = ON;

Example –

ALTER LOGIN geeks WITH CHECK_POLICY = OFF;

ALTER LOGIN geeks WITH CHECK_POLICY = ON;
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.