Platform SDK: Active Directory, ADSI, and Directory Services

SQL Dialect

Derived from the Structured Query Language, the SQL dialect uses more human-readable expressions to define query statements. SQL statements have the following syntax:

SELECT [ALL] select-list FROM 'ADsPath' [WHERE search-condition] [ORDER BY sort-list]

Where SELECT (may be followed by ALL) and FROM are the required keywords and WHERE and ORDER BY are the optional keywords.

The following are examples of query statements of the SQL dialect in ADSI.

To search for all the group objects:

SELECT ADsPath, cn FROM 'LDAP://DC=Fabrikam,DC=COM' WHERE objectCategory='group'

To search for all the users whose Last Name starts with letter H:

SELECT ADsPath, cn FROM 'LDAP://OU=Sales, DC=Microsoft,DC=COM' WHERE objectCategory='person' AND objectClass='user' AND sn = 'H*' ORDER BY sn

The formal grammar for SQL queries is defined in the following way. (All keywords are case insensitive.)

statement ::= select-statement
select-statement ::= SELECT [ALL] select-list FROM table-identifier [WHERE search-condition] 
select-list ::= * | select-sublist [, select-sublist]... 
select-sublist ::= column-identifier
column-identifier ::= user-defined-name 
table-identifier ::= string-literal
search-condition ::= boolean-term [OR search-condition]
boolean-term ::= boolean-factor [AND boolean-term]
boolean-factor ::= [NOT] boolean-primary
boolean-primary ::= comparison-predicate | (search-condition)
comparison-predicate ::= column-identifier comparison-operator literal
comparison-operator ::= < | > | <= | >= | = | <>
user-defined-name ::= letter [letter | digit]...
literal ::= string-literal | numeric-literal | boolean-literal 
string-literal ::= '{character}...' (Any sequence of characters delimited by quotes)
numeric-literal ::= digits [fraction] [exponent]
digits ::= digit [digit]...
fraction ::= . digits 
exponent ::= E digits
boolean-literal ::= TRUE | FALSE | YES | NO | ON | OFF