After connecting you can
either use SSMS or T-SQL to change the sa password. To use SSMS navigate to the
Security node and then expand Logins and right click the sa login to change the
Password properties.
Alternatively you can
select New Query from the SSMS menu to open Query Editor and then run the
following T-SQL query to reset the password for the sa login.
GO
ALTER LOGIN [sa] WITH DEFAULT_DATABASE=[master]
GO
USE [master]
GO
ALTER LOGIN [sa] WITH PASSWORD=N'NewPassw0rd'
GO
GO
USE [master]
GO
ALTER LOGIN [sa] WITH PASSWORD=N'NewPassw0rd'
GO
That’s all pretty easy
but what if you don’t have access an account that isn’t included in the
sysadmin role? Fortunately, beginning with SQL Server members of the
Windows Administrators group can access SQL Server in single-user mode. This
allows you to add a login to the sysadmin role which you can then use to start
SQL Server with administrative rights. The account needs to be a member of the
local administrators group.
To start SQL Server in
single-user mode add the parameter -m at the command line. The easiest way to
do this is to use Configuration Manager. Stop the SQL Server Instance you want
to change. Right click the instance to open the Properties dialog and click the
Startup Parameters tab. Enter –m in the Startup parameters option.
SQLServerManager13.msc SQLServer2016
SQLServerManager12.msc SQLServer2014
SQLServerManager11.msc SQLServer2012
SQLServerManager10.msc SQLServer2008
EXEC sp_addsrvrolemember
'CONTOSO\mikeo2', 'sysadmin';
GO
GO
This example adds the
account CONTOSO\mikeo2 to the SQL Server sysadmin role. Next, use Configuration
Manager to stop the SQL Server services and remove the -m from the Startup
Parameters. Then restart the SQL Server service. You should be able to login with
sysadmin rights using the account you added. Then you change the sa password
using one of the techniques presented earlier.