Contents 

Ubitsoft SQL Enlight Online Help

Analyze a selection of T-SQL code
Analyze SQL Server objects in SSMS
Analyze before Execute or Parse SQL Commands
Analysis Context
Analysis Result

Using the Analyze Script command you can run static analysis over your T-SQL script or run it over SQL Server objects.

Analyze a selection of T-SQL code

1. Set active rules in the Analysis Rules using the Analysis tab.

Analyze T-SQL Script Example 1 -

2. Select SQL code or clear selection in order to analyze the whole active document.

3. Use Static Analysis -> Analyze with All Rules to analyze with all active rules or Static Analysis -> Analyze with Specific Rules... to select rules. The commands are available either from the SQL Enlight menu or toolbar. Analyze with All Rules command is accessible also by the Ctrl + Alt + A keyboard shortcut.

Explicit analysis rules are directly available in the Static Analysis sub menu. These rules are managed in the Explicit Rules analysis group and due to their kind are available only to be used separately from the general rules.

Analyze T-SQL Script Example 2

4. If the Analyze with Specific Rules... command is used the following rule selector dialog will appear:

Analyze T-SQL Script - Rules Selector


By default only Batch scoped analysis rules will be applied when analyzing a T-SQL sript using the Analyze with All Rules command. The Context Only analysis rules can be applied only if they are explicitly selected using the Analyze with Specific Rules... command.

5. The Analysis Parameters dialog will appear if any of the selected analysis rules has parameters and its setting Always require parametrs to be set is checked. However the parameters dialog will show all the parameters of the active parameterized analysis rules.

Analyze T-SQL Script - Paraeters Selector

Analyze database stored procedures,function and triggers in SQL Server Management Studio

1. Right click object in SQL Server Management Studio's Object Explorer to open the context menu.

Analyze T-SQL Script Example 4

2. Use the 'Static Analysis' menu to select SQL Enlight command,specific group or rule. The menu will be available If the selected object or one of its children can be analyzed.

3. Select analysis rules if the Analyze with Specific Rules... command is used.

4. The Analysis Parameters dialog will appear if any of the selected analysis rules has parameters and its setting Always require parametrs to be set is checked. However the parameters dialog will show all the parameters of the active parameterized analysis rules.

5. The command will script the stored procedures, functions and triggers under the selected object in a new query window and will analyze the resulting script.


By default only Batch scoped analysis rules will be applied when analyzing a T-SQL sript using the Analyze with All Rules command. The Context Only analysis rules can be applied only if they are explicitly selected using the Analyze with Specific Rules... command or the object being analyzed is a database or a server.

Analyze before Execute or Parse SQL Commands

Static analysis can be configured to run before T-SQL Execute or Parse commands. If analysis rule violations are found the execution of the T-SQL code can be cancelled.

The settings are available either in the Static Analysis menu or in the SQL Enlight->Options->Settings->Analysis Settings.

Analysis Context

Analysis context is the current connection database context information retrieved before analysis command is executed. The loaded analysis context is passed to the analysis rules. This allows the rules to use all available database schema information.

For more information how to use the analysis context in the see Create Custom Analysis Rules topic.

Analysis Result

If there are T-SQL script analysis rules violations, the SQL Enlight Error List Window will be displayed and the violations will be marked in the text editor.

SQL Enlight Error List Window Example 3

Double-click any error message entry to open the file where the problem occurs, and move to the error location.

To sort the list, click any column header.

For simple exporting the results to excel as or text file, the Copy to Clipboard keyboard shortcut Ctrl+C is available. The command line tool can also be used for generating the analysis report and output the analysis report in XML file.

Use the Errors, Warnings, and Messages buttons to select which entries to display.

Errors

Indicates the number of Errors in the list. Click to toggle whether Errors are displayed.

Warnings

Indicates the number of Warnings in the list. Click to toggle whether Warnings are displayed.

Messages

Indicates the number of Messages in the list. Click to toggle whether Messages are displayed.