How to work with T-SQL Code Analyzer
Last modified: September 6, 2024
Enable T-SQL Code Analyzer
To enable the T-SQL Code Analyzer, in the SQL document, enter the code you want to validate. Right-click the SQL document body and select Analyze Code.
Note
T-SQL Code Analyzer validates code only in the active SQL document and only after you select Analyze Code. It does not automatically analyze code as you write.
Inspect issues
To analyze the code in your SQL document against the code analysis rules of your active profile, right-click the body of the SQL document and select Analyze Code. Once SQL Complete finishes the analysis, non-compliant code is underlined with a green wavy line. Hover over the underlined code fragment to view the issue details. Additionally, the results of the code analysis are displayed in both the Error List and Output windows.
T-SQL Code Analyzer output
Code analysis output in the Error List
When the T-SQL Analyzer identifies code that violates the rules, it displays one of the following message types in SSMS or Visual Studio Error List: Warning,
, Error, and
Hint.
The Error List presents the T-SQL Code Analyzer output in a table format. The Code column displays the rule identifier, clicking which will open a detailed description of the rule in the product documentation. The Description column contains the rule title. The File column shows the document name where the analysis is being conducted, and the Line column shows the line number where the rule was triggered. For additional details about the rule, click the Expand icon at the beginning of the row.
Code analysis output in the SQL document
When a rule is triggered in a SQL document, the corresponding code is underlined with a wavy line. Hovering over this code displays a hint with the rule details.
Code analysis info in the Output window
Information regarding the results of code analysis is also displayed in the Output window of SSMS.
Enable and disable code analysis rules
You can customize T-SQL Code Analyzer by disabling rules that you do not find useful to reduce the number of issues in your script.
To view the list of all rules and enable or disable them individually, navigate SQL Complete > Options > Code Analysis > Profiles. Then select the active profile and click Open Selected. In the dialog that opens, you can select the code analysis rules you want to apply to your code. By default, all the rules are selected. If you want to exclude the rule from the profile settings, clear the corresponding checkbox.
SQL Complete allows the user to create multiple custom code analysis profiles. For more details, refer to Customize T-SQL Code Analyzer.