Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I script a password change for a SQL server login?

Tags:

Just what the title says, I need to change the password for an existing sql server login and I want to do it via sql script.

like image 874
Larry Foulkrod Avatar asked Sep 11 '08 15:09

Larry Foulkrod


People also ask

What two methods can be used to change a user's password in SQL?

Change Password NOTE: A DBA or somebody with sufficient privilege can change the existing password of a user and create a new user. Database to which the user is permitted to be work. User id of the user whose password you are changing.

How do I change a user password in SQL?

Click on Security and make sure that SQL Server and Windows Authentication mode is selected. Then click OK. In the Object Explorer expand Security>Logins and then right click on the user to change the password. Change the password and confirm the change.


1 Answers

If the user already has the ALTER ANY LOGIN permission (i.e. the user can change any password for any user) then this works:

alter login mylogin with password = 'mylogin' 

Otherwise, if you don't want to make every user in your system a superuser, add a parameter of the old password for the same command:

alter login mylogin with password = 'mylogin' old_password='oldpassword' 
like image 139
Nagendra Mishr Avatar answered Oct 19 '22 08:10

Nagendra Mishr