SQML Schema Reference

SQL Enlight uses an XML DOM language to describe T-SQL statements called SQML which stands for Structured Query Markup Language.

T-SQL batch as SQML:

1<g:batch>
2<g:statements>
3  <pu:semicolon>
4    <g:statement>
5        ...
6    </g:statement>
7  </pu:semicolon>
8</g:statemetns>
9</g:batch>

SQML elements are separated into different categories which  have specific
namespaces.

1<g:batch>
2<g:statements>
3  ...
4    <g:statement>
5  ...
6    </g:statement>
7  ...
8</g:statemetns>
9</g:batch>

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

Element

Description

batch SQML root element.
statements Element containing multiple statement elements. This element mostly appears as a child of the batch element.
statement Container for T-SQL statement.
brackets The expression inside parentheses is written as a child of this element.
expression Appears as the parent element of arithmetic expressions.
boolean-expression Appears as the parent element of logical expressions.
commalist The 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:”. SQML 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:

Attribute

Description

name Operator name is written in this attribute. It is stored in lowercase.

T-SQL arithmetic expression:

1a + b + 1

SQML:

1<g:expression>
2     <o:additive name="+">
3             <o:additive name="+">
4                <i:common name="a"/>
5                <i:common name="b"/>
6             </o:additive>
7           <co:exact-number>1</co:exact-number>
8     </o:additive>
9</g:expression>

T-SQL logical expression:

1a>1 and b = 3

SQML:

 1<g:boolean-expression>
 2<k:and>
 3  <o:comparison name=">">
 4    <g:expression>
 5      <i:common name="a"/>
 6    </g:expression>
 7    <g:expression>
 8      <co:exact-number>1</co:exact-number>
 9    </g:expression>
10  </o:comparison>
11  <o:comparison name="=">
12    <g:expression>
13      <i:common name="b"/>
14    </g:expression>
15    <g:expression>
16      <co:exact-number>3</co:exact-number>
17    </g:expression>
18  </o:comparison>
19</k:and>
20</g:boolean-expression>

 

Identifiers

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

Element

Description

delimited Delimited identifier.
quoted Quoted identifier.
labels Label name.
common Common 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:

Attribute

Description

name Identifier name is written in this attribute.

T-SQL multipart identifier:

1server_name.[database_name].[schema_name].object_name

SQML:

 1<pu:dot>
 2  <i:common name="server_name"/>
 3    <u:dot>
 4      <i:delimited name="database_name"/>
 5      <u:dot>
 6        <i:delimited name="schema_name"/>
 7      <i:common name="object_name"/>
 8    </u:dot>
 9  </u:dot>
10</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:”.

Element

Description

string Literal string.
exact-number Integer number.
float-number Floating point number.
hex Hexadecimal number.
money Currency number.
bool Boolean 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:

13
2
3'literal string'

SQML:

1<co:exact-number>3</co:exact-number>
2
3<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:”.

Element

Description

singleline Single line comment.
multiline Block comment.

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

T-SQL:

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

SQML:

 1<k:select>
 2  <g:commalist>
 3  ...
 4  </g:commalist>
 5  <k:from>
 6  <g:commalist>
 7    <i:common name="table1">
 8      <cmt:multiline>/* test comment */</cmt:multiline>
 9    </i:common>
10  </g:commalist>
11  </k:from>
12</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:’.

Element

Description

local Local variables ( @variable ).
global Global variables ( @@variable ).
server Server functions ( @@SERVERNAME, @@CONNECTIONS, @@VERSION, @@LOCK_TIMEOUT and etc. ).

The elements from this group has these attributes:

Attribute

Description

name Variable 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:”.

Element

Description

simple Common punctuation element.

Element is now obsolete and is not used.

binding Binding punctuation ( like ‘.’ in the multipart identifier names).

Element is now obsolete and is not used.

optional Optional punctuation ( like ‘;’ ).

Element is now obsolete and is not used.

semicolon Replaces pu:essential[@name=’;’] and pu:optional[@name=’;’] elements.
dot Replaces pu:binding[@name=’.’] element.

The elements from this group has these attributes:

Attribute

Description

name Attribute is now obsolete and is not used.

Example SQML:

1<g:batch>
2<g:statements>
3  <pu:semicolon>
4    <g:statement>
5     ...
6    </g:statement>
7  </pu:semicolon>
8</g:statements>
9</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.

Element

Description

unknown The only element in this category.

The elements from this group has these attributes:

Attribute

Description

value The 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:”.

Element

Description

datatype SQL data types.
aggregate T-SQL aggregate functions (COUNT,AVG,SUM and etc.).
function The possible values are CAST and COLUMNS_UPDATED.
sizeunit Size units. The possible values are KB,MB,GB and TB.
dbcc-option DBCC statement options.
backup-option Backup statement options.
bulk-option Bulk statement options.
setting-option SET statement options.
hint Table 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

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:

Attribute

Description

name The 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.

Attribute

Description

sline Start line number.
eline End line number.
scol Start column.
ecol End column.
type Token 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 SQML:

1<g:batch se:sline="1" se:scol="0" se:eline="2" se:ecol="30">
2<g:statements>
3  <pu:semicolon se:sline="1" se:scol="0" se:eline="1" se:ecol="1" se:type="opt+">
4    <g:statement se:sline="1" se:scol="0" se:eline="2" se:ecol="30">
5    ...
6    </g:statement>
7  </pu:semicolon>
8</g:statements>
9</g:batch>

See Also