Skip to content

Syntax Tree Schema Reference

SQL Enlight uses an XML DOM language to describe T-SQL statements syntax tree.

T-SQL batch as syntax tree:

<g:batch>
<g:statements>
<pu:semicolon>
<g:statement>
...
</g:statement>
</pu:semicolon>
</g:statemetns>
</g:batch>

Syntax tree elements are separated into different categories which  have specific namespaces.

<g:batch>
<g:statements>
...
<g:statement>
...
</g:statement>
...
</g:statemetns>
</g:batch>

Namespace for all container elements.The namespace prefix is “g:”.

ElementDescription
batchSyntax tree root element.
statementsElement containing multiple statement elements. This element mostly appears as a child of the batch element.
statementContainer for T-SQL statement.
bracketsThe expression inside parentheses is written as a child of this element.
expressionAppears as the parent element of arithmetic expressions.
boolean-expressionAppears as the parent element of logical expressions.
commalistThe content of this element is a list of elements that in the T-SQL statement appear as a comma-separated list.

Operators

All arithmetic and bitwise operators are scoped in this namespace. The namespace prefix is “o:”. The syntax tree uses prefix notation (Polish notation) to descried arithmetic and logical expressions. The operator is the parent element and operands are written as child elements. The first child represents the left operand and the second child represents the right operand in the expression.

| Element | Description | | -------------- | ------------------------------------------- | --- | | additive | + - | | multiplicative | * / % | | assignment | += -= *= /= %= &= ^= | = | | bitwise | ~ ^ & | | | comparison | < > != = <> <= >= !< !> | | shift | << >> | | unary | - + | | old-outer-join | Old style outer join operators : = and =. |

The elements from this group has these attributes:

AttributeDescription
nameOperator name is written in this attribute. It is stored in lowercase.

T-SQL arithmetic expression:

a + b + 1

Syntax tree:

<g:expression>
<o:additive name="+">
<o:additive name="+">
<i:common name="a"/>
<i:common name="b"/>
</o:additive>
<co:exact-number>1</co:exact-number>
</o:additive>
</g:expression>

T-SQL logical expression:

a>1 and b = 3

Syntax tree:

<g:boolean-expression>
<k:and>
<o:comparison name=">">
<g:expression>
<i:common name="a"/>
</g:expression>
<g:expression>
<co:exact-number>1</co:exact-number>
</g:expression>
</o:comparison>
<o:comparison name="=">
<g:expression>
<i:common name="b"/>
</g:expression>
<g:expression>
<co:exact-number>3</co:exact-number>
</g:expression>
</o:comparison>
</k:and>
</g:boolean-expression>

Identifiers

There are four kinds of identifiers delimited, quoted, labels common. The Namespace prefix is “i:”.

ElementDescription
delimitedDelimited identifier.
quotedQuoted identifier.
labelsLabel name.
commonCommon non-delimited identifier.

Multipart identifiers are represented using prefix notation as the parent element is the pu:binding[@name=”.”].The child elements are the left and the right identifier elements.

The elements from this group has these attributes:

AttributeDescription
nameIdentifier name is written in this attribute.

T-SQL multipart identifier:

server_name.[database_name].[schema_name].object_name

Syntax tree:

<pu:dot>
<i:common name="server_name"/>
<u:dot>
<i:delimited name="database_name"/>
<u:dot>
<i:delimited name="schema_name"/>
<i:common name="object_name"/>
</u:dot>
</u:dot>
</u:dot>

Clauses

All T-SQL clauses are in this category. The namespace prefix is “c:”. The names of the elements which belong to this category are the names of actual T-SQL clauses. The names are in lowercase.

Constants

All constant values are in this category. The values of elements from this namespace are written as element content. The namespace prefix is “co:”.

ElementDescription
stringLiteral string.
exact-numberInteger number.
float-numberFloating point number.
hexHexadecimal number.
moneyCurrency number.
boolBoolean value (true, false).
extended-sql ( extended SQL is handled as a constant string )Extended SQL expression is written as a literal string expression and is contained in this element.

TSQL:

3
'literal string'

Syntax tree:

<co:exact-number>3</co:exact-number>
<co:string>'literal string'</co:string>

Comments

The comments in the T-SQL script are in this category. The comments are stored as content of the element. The namespace prefix for this category is “cmt:”.

ElementDescription
singlelineSingle line comment.
multilineBlock comment.

Comment elements are attached to the last token before the comment itself.

T-SQL:

SELECT column1, column2 FROM table1 /* test comment */

Syntax tree:

<k:select>
<g:commalist>
...
</g:commalist>
<k:from>
<g:commalist>
<i:common name="table1">
<cmt:multiline>/* test comment */</cmt:multiline>
</i:common>
</g:commalist>
</k:from>
</k:select>

Variables

This is a category for the T-SQL variables. The variable name is written in the name attribute. The namespace prefix for this category is ‘v:’.

ElementDescription
localLocal variables ( @variable ).
globalGlobal variables ( @@variable ).
serverServer functions ( @@SERVERNAME, @@CONNECTIONS, @@VERSION, @@LOCK_TIMEOUT and etc. ).

The elements from this group has these attributes:

AttributeDescription
nameVariable name is written in this attribute.

Keywords

All T-SQL reserved keywords are in this category. The namespace prefix is “k:”. The names of the elements which belong to this category are the names of actual T-SQL reserved keywords. The names are in lowercase.

Punctuation

The namespace prefix for this category is “pu:”.

ElementDescription
simpleCommon punctuation element. Element is now obsolete and is not used.
bindingBinding punctuation ( like ’.’ in the multipart identifier names). Element is now obsolete and is not used.
optionalOptional punctuation ( like ’;’ ). Element is now obsolete and is not used.
semicolonReplaces pu:essential[@name=’;’] and pu:optional[@name=’;’] elements.
dotReplaces pu:binding[@name=’.’] element.

The elements from this group has these attributes:

AttributeDescription
nameAttribute is now obsolete and is not used.

Example syntax tree:

<g:batch>
<g:statements>
<pu:semicolon>
<g:statement>
...
</g:statement>
</pu:semicolon>
</g:statements>
</g:batch>

Unknown

This category holds the T-SQL syntax elements which do not fall in any of the other categories. We are working on removing such elements, but there are a few left. The namespace prefix for this category is “u:”. The only element which belongs here is the ‘unknown’ element.

ElementDescription
unknownThe only element in this category.

The elements from this group has these attributes:

AttributeDescription
valueThe value of the not categorized token is written in this attribute.

Predefined

This category includes well-known T-SQL object names (such as data types, set options, hints and etc.) which have specific scope and usage in the T-SQL grammar. The namespace prefix for this category is “pr:”.

ElementDescription
datatypeSQL data types.
aggregateT-SQL aggregate functions (COUNT,AVG,SUM and etc.).
functionThe possible values are CAST and COLUMNS_UPDATED.
sizeunitSize units. The possible values are KB,MB,GB and TB.
dbcc-optionDBCC statement options.
backup-optionBackup statement options.
bulk-optionBulk statement options.
setting-optionSET statement options.
hintTable hints and query hints. Possible values:READCOMMITTED REPEATABLEREAD READUNCOMMITTED FASTFIRSTROW PAGLOCK ROWLOCK SERIALIZABLE TABLOCK TABLOCKX UPDLOCK NOLOCK READPAST CONCAT FAST FORCE HASH KEEP LOOP MAXDOP MERGE XLOCK ROBUST REMOTE NOEXPAND KEEPDEFAULTS IGNORE_CONSTRAINTS IGNORE_TRIGGERS READCOMMITTEDLOCK OPTIMIZE KEEPFIXED EXPAND VIEWS MAXRECURSION QUERYTRACEON

⚡ ** note: ** Note: The hints and the reserved keywords fall in the Keywords category.

| | built-in-function | The function names of system table functions invoked as in SQL Sever 2000 without the ”::” prefix. | | collation-name | Collation name. | | column-ref | The reference to specific system column or function.Possible values:$ROWGUID $IDENTITY $PARTITION $ACTION | | event-notification | Event names and event group names. |

The elements from this group has these attributes:

AttributeDescription
nameThe attribute holds the name of the predefined element.

System

SQL Enlight adds some specific attributes which to be later used by the analysis engine. The attributes specify the position of the tokens and optionally their type.

AttributeDescription
slineStart line number.
elineEnd line number.
scolStart column.
ecolEnd column.
typeToken type. This attribute is optional and currently is used only to specify if the given element is inserted by the engine or not. Possible values: “opt” - specifies that the element is optional and can be omitted “opt+” - the element is optional and was explicitly added.

The namespace prefix is “se:”.

Example syntax tree:

<g:batch se:sline="1" se:scol="0" se:eline="2" se:ecol="30">
<g:statements>
<pu:semicolon se:sline="1" se:scol="0" se:eline="1" se:ecol="1" se:type="opt+">
<g:statement se:sline="1" se:scol="0" se:eline="2" se:ecol="30">
...
</g:statement>
</pu:semicolon>
</g:statements>
</g:batch>

Analysis Rules

Manage Analysis Rules