Change the Password on the SA Login in SQL Server (T-SQL Example)

Below is an example of the T-SQL code you can use to change the password of the sa login account in SQL Server.

The sa account’s password can be changed with the ALTER LOGIN statement.

Example of Changing the Password

Here’s an example.

USE Master;
ALTER LOGIN [sa] WITH PASSWORD = N'newpassword' 

Be sure to replace newpassword with a very strong password.

Example of Changing the Password While Logged in as the Login

Here’s what you’ll need to do if you’re already logged in using the sa account.

USE Master;
ALTER LOGIN [sa] WITH PASSWORD = N'newpassword' OLD_PASSWORD = N'oldpassword';

Again, be sure to replace newpassword with a very strong password.

In addition to change the sa password, it’s actually good security practice to disable the sa account altogether and then create new logins for admin purposes. Also consider renaming the sa account before disabling it, as this will add another layer of protection to your environment.