SA0222 : The ALTER LOGIN WITH SET CREDENTIAL or ALTER LOGIN WITH NO CREDENTIAL syntax is deprecated |
![]() |
Using the deprecated ALTER LOGIN with the SET CREDENTIAL option in T-SQL code may lead to compatibility issues in future SQL Server versions.

Many versions of SQL Server have deprecated certain features, which are considered outdated and might be removed in future releases. The T-SQL syntax ALTER LOGIN WITH SET CREDENTIAL or NO CREDENTIAL is one such feature. Using deprecated features can cause unexpected behavior and complicate future upgrades.
For example:
1-- Example of deprecated query 2ALTER LOGIN [userName] WITH SET CREDENTIAL = credentialName;
This expression is problematic because it leverages a syntax no longer recommended for managing credentials. Continued use can lead to difficulties in maintaining the database as SQL Server evolves, forcing developers to revise existing scripts during migration or upgrade tasks.
-
Deprecated syntax can lead to code interruptions in future SQL Server versions.
-
Makes code maintenance harder due to reliance on obsolete practices.

To resolve issues related to deprecated T-SQL syntax for managing credentials, use the recommended syntax with ALTER LOGIN ADD/DROP CREDENTIAL.
Follow these steps to address the issue:
-
Identify the instances in your scripts where ALTER LOGIN WITH SET CREDENTIAL or NO CREDENTIAL is used.
-
Replace the deprecated syntax with the appropriate ALTER LOGIN ADD CREDENTIAL statement to add a credential.
-
Use ALTER LOGIN DROP CREDENTIAL to remove a credential, if necessary.
For example:
1-- Example of corrected query 2ALTER LOGIN [userName] ADD CREDENTIAL credentialName;

The rule has a Batch scope and is applied only on the SQL script.

Rule has no parameters.

The rule does not need Analysis Context or SQL Connection.


Deprecated Features, Bugs


SQL
1ALTER LOGIN Joe2 WITH CREDENTIAL = Custodian04; 2ALTER LOGIN Joe2 WITH NO CREDENTIAL 3 4ALTER LOGIN Joe2 ADD CREDENTIAL Custodian04; 5ALTER LOGIN Joe2 DROP CREDENTIAL Custodian04; |

Message | Line | Column | |
---|---|---|---|
1 | SA0222 : The ALTER LOGIN WITH SET CREDENTIAL or ALTER LOGIN WITH NO CREDENTIAL syntax is deprecated. | 1 | 17 |
2 | SA0222 : The ALTER LOGIN WITH SET CREDENTIAL or ALTER LOGIN WITH NO CREDENTIAL syntax is deprecated. | 2 | 17 |
