How to Change SQL SA Password from a Command Prompt
Don't know how to use the command prompt to change the SA password in MSSQL Server? Despite other ways to change the SA password (like using SQL Server Management Studio or resetting SA password by Cocosenor SQL Password Tuner), SQL command lines(SQLCMD) utility could be another efficient tool to help reset the MS SQL Server SA password directly.
No matter whether you remember the SA password or not, SQLCMD utility from a command prompt can easily change or reset the SA password without running any other software. The content of this page is about two different ways to reset the SA password by SQLCMD commands in Command Prompt especially when forgetting or losing the password
- Guide to Reset/Change SQL SA password from Command Prompt:
- Part-1: use SQLCMD utility to reset SA password
- Part-2: reset and change MS SQL SA password from command promptĀ
Change SQL SA Password from Command Prompt
Use SQLCMD utility to Reset SA password in MS SQL Sever
This is going to change and reset a new sa password for your SA login account in MS SQLServer. We need to run the Command prompt and then execute the SQLCMD commands. Follow the steps below.
1. Click Search bar to find out the SQLCMD and run it. Or run Command Prompt as the administrator and then access the SQLCMD utility.
2. In the interface of the command lines. Execute the command and press the key of Enter: sqlcmd. (If you already run the SQLCMD, ignore this step.)
3. Type command: sp_password @new = 'newpassword', @loginame = 'sa'. (Replace the newpassword with the real new password you want to reset for the SA user account. And then press Enter.)
4. Then type go and press Enter.
Here's another similar way to reset the MSSQL Server SA password by the SQLCMD from the Command Prompt. It's more for the case when your SA login account is locked out. Follow the steps to change the SA password from the Command Prompt.
1. Search the SQLCMD and click to run it. Or Click Start to run the Command Prompt as the administrator.
2. In the interface of the command lines, execute the command: sqlcmd -S SQLSERVER\INSTANCE. (Replace the SQLSERVER\INSTANCE with your sever name. And then press Enter. If you already run the SQLCMD, ignore this step.)
3. Type the command: ALTER LOGIN sa WITH PASSWORD = 'newpassword' UNLOCK. Replace the newpassword with a new password you want and then press Enter.
4. Then type go and press Enter.
Note: if you don't remember the server name, the command, osql -L, in the picture above can help list the Servers name for you.
More: reset and change MS SQL SA password from command prompt
It's an optional way for you to use SQLCMD utility to modify any login password. And it is more for the case when you could remember the old SA password but want to reset a new one. Follow the steps below, executing SQLCMD commands in command prompt to set a new password.
1. Run up the Command Prompt on your computer.
2. Type command:
sqlcmd -U someuser -P currentpassword -z newpassword.
3. Type go and press Enter.