There was a question today How to change my local sql server sa password? i would like to expand on my answer in this post
Before I start I would like you to read this post by ted Krueger first: To SA or not to SA to understand why you should not be using the SA account.
Now that you know why you should not be using the SA account and you are still using it, let's see how you can change the password for the SA account
The easiest way is to login to the server as sa or any other account that has sufficient privileges to change the sa account
here is what the script looks like
- USE [master]
- ALTER LOGIN [sa] WITH PASSWORD=N'NewPassword'
Most likely you will get this error
Msg 15118, Level 16, State 1, Line 1
Password validation failed. The password does not meet Windows policy requirements because it is not complex enough.
There are two things you can do, the smarter thing would be to pick a complex password with some digits and some characters that are not alphanumeric. Or you can shoot yourself in the foot by turning the check off
- USE [master]
- ALTER LOGIN [sa] WITH PASSWORD=N'NewPassword', CHECK_POLICY =OFF
Now try to login. It is possible that the sa account is disabled, you will see the following message
Login failed for user 'sa'. Reason: The account is disabled. (Microsoft SQL Server, Error: 18470)
To enable the account, all you have to do is the following
- ALTER LOGIN [sa] ENABLE
You do not need to restart the SQL Server service for a password change. One of the myths that you will hear is that you need to restart SQL Server. When you change from SQL authentication to mixed authentication and vice versa, you do need to restart for the changes to take effect but for a password change it is immediate, no need for a restart!
And if you are old school, you can also do the following, thanks to Aaron Bertrand for this
- EXEC sp_password N'old password', N'new password', N'sa';
You can also do all of this from SSMS with the GUI, navigate to the security folder, right click on the sa account, select properties and you will see the following window
Click on the Status page to enable or disable the account
I would encourage you to use T-SQL not the GUI, the day (and I promise you this will happen) will come that sql server will be installed on a box without the tools (Sever core perhaps) and you can only connect to it from the command line with osql, you will be stuck if you don't know how to do this with T-SQL