-- Change SA Password in SQL Server Using TSQL Query
USE master
GO
ALTER LOGIN [sa] WITH PASSWORD=N'NewSAPassword'
GO
-- F5
-- Run this query in SQL Server.
-- NewSAPassword is your new password, you can give another password also instead of
-- NewSAPassword.
-- You might be receive the below mentioned error message as the password specified does
-- not meet windows policy requirements because it is not complex enough.
-- Error Message
-- 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.
-- It is always a best practice to set a complex password for an SA (System
-- Administrative Account) in SQL Server to avoid unauthorized access.
-- If you still want to set a simple password for an SA account in SQL Server which is
-- not recommended; then you add CHECK_POLICY = OFF clause to the above query.
USE master
GO
ALTER LOGIN [sa] WITH PASSWORD=N'NewSAPassword', CHECK_POLICY = OFF
GO
--F5
-- There may be a scenario that once you try logging in to SQL Server using SA Password
-- you get the below mentioned error.
-- Error Message
-- Login failed for user 'sa'. Reason: The account is disabled. (Microsoft SQL Server,
-- Error: 18470)
-- Enable SA Account in SQL Server
-- In such a scenario you need to go ahead and run the below TSQL code to enable SA
-- account in SQL Server.
USE master
GO
ALTER LOGIN [sa] ENABLE