Click or drag to resize

How To: Create Analysis Rule with Rule Designer

This topic describes the steps to create a new analysis rule using the Analysis Rule Designer.

Create a new analysis rule
  1. Open SQL Enlight Options dialog and go to the Analysis > Rules tab.


  2. Select an analysis group which will be parent group of the rule

  3. Open group's context menu and use the New -> Batch Rule or New -> Context Only Rule commands

Set rule properties

The analysis rule properties can be set in on the Rule > Details tab:


There are several properties which can be configured:


Unique name which to identify the rule. This is a required field that can contain only alphanumeric characters.

The field can be referenced inside the XSLT rule expression using the $v-rulename.

Short Description

Short message which usually (but not necessarily) is displayed when the rule is triggered.

The field can be referenced inside the XSLT rule expression using the $v-ruledescription.


More detailed description of the rule.

The field is only informational and cannot be referenced inside the rule expression.


Informational field that can contain the author of the rule.


The filed contains the rule severity level and can have one of the following values:

  • Error

  • Warning

  • Information

  • Task and Undefined

The field can be referenced inside the XSLT rule expression using the $v-ruleseverity.


The field determines the scope of the rule – Batch or Context Only.

Set parameters

The analysis rule parameters can be set on the Parameters tab.


A single analysis rule parameter can have none or several predefined values from which the user will be able to choose before executing the Static Code Analysis command.

The Always require parameters to be set check box will make the Analysis Parameters dialog always appear when the rule is applied.

If this option is not checked, the default values of the parameters will be used.

Modify rule expression

Refer to Analysis Rule topic to learn more about the analysis rule expression.

The editor at the Expression tab can be used to enter and edit the rule's XSLT expression.


Use the toolbar buttons to edit, format and validate the XSLT expression.

Any XML or XSLT errors messages found during expression validation will be displayed in the Error List and the error will be marked inside the analysis rule expression.

Analysis Context

The Test Analysis Context tab contains the context XML which is used for testing the analysis rule.


The toolbar also contains a XPlath test field which can be used to test XPath expressions against the loaded context and see the results in the Errors List.

The connection to the default Analysis Context which to be used for rule testing can be set on the SQL Enlight -> Options menu, an on the Analysis -> Options -> Context tab:


This connection will be used by default in the Analysis Rule Designer to load the context when testing the rule.

The setting can be overridden and the connection can be changed in the designer with the Connection... button located on the Test Analysis Context tab toolbar.

Use the XML Tree tab to examine the Analysis Context and also generate sample XPath expression to the selected node.


Analysis context can be accessed inside the rule expression using the $context variable.

The current context database can be accessed with the $database variable.


1<xsl:value-of select="$context/Database[1]/Tables/Table[1]/@Name"/>
2<xsl:value-of select="$database/Tables/Table[1]/@Name"/>

Refer to the Analysis Context topic to learn more.

Test rule's XSLT expression

When creating an analysis rule you can test the rule expression it against real T-SQL script and see whether it gives expected result.


You can also use the XML view of the T-SQL script to examine the script's SQML and test XPath expressions.


The test script is saved with the rule and can be reused is loaded when the rule is opened in the designer.

Use the Test Rule button to run the analysis rule over the test SQL script and see if the rule is evaluating correctly.

Note Note

Rule expression debugging is not supported by the Analysis Rule Designer and is only possible when the rule is implemented as a project using Visual Studio.

See How To: Create Analysis Rule with Visual Studio topic for more information.

See Also