views:

209

answers:

4

Is there a name for a syntax used for SQL?

E.g.) When you go to this page on BOL (SQL Books OnLine),
it shows the syntax of BEGIN DIALOG CONVERSION

BEGIN DIALOG [ CONVERSATION ] @dialog_handle
   FROM SERVICE initiator_service_name
   TO SERVICE 'target_service_name'
    [ , { 'service_broker_guid' | 'CURRENT DATABASE' } ] 
   [ ON CONTRACT contract_name ]
   [ WITH
   [  { RELATED_CONVERSATION = related_conversation_handle 
   | RELATED_CONVERSATION_GROUP = related_conversation_group_id } ] 
   [ [ , ] LIFETIME = dialog_lifetime ] 
   [ [ , ] ENCRYPTION = { ON | OFF }  ] ]
[ ; ]

What is the name/terminology of the syntax used above?

Transact-SQL Syntax Conventions (Transact-SQL) does not mention the name of their "Syntax Conventions".

A: 

I agree with Liao.

There is more to it. This is used not just for SQL syntax but to describe/define grammars of various artificial languages (programming languages belonging here as well).

User
A: 

I've seen this sort of syntax description for a long time. If you're interested in ancient history, take a look at the TOPS-10/TOPS-20 COBOL-74 Language Manual (AA-5059B-TK).

John Saunders
A: 

I don't know whether this notation has a specific name, but it is not BNF - Backus-Naur Form, nor is it EBNF (extended BNF, aka ISO/IEC 14977:1996). It is loosely related, but only loosely related. In particular, BNF specifies that a non-terminal name is defined as some list of values. An example would be this CREATE TABLE statement from the SQL 2003 standard:

<table definition> ::=
     CREATE [ <table scope> ] TABLE <table name> <table contents source>
     [ ON COMMIT <table commit action> ROWS ]

The LHS ('<table definition>') is a non-terminal that can be referenced elsewhere. The '::=' operator is the 'is defined as' operator. The terms in angle brackets '<>' are more non-terminals (sometimes the same as the LHS, though not in this example), for which there is a definition somewhere else. The parts in square brackets '[ ... ]' are optional (may either be present - once - or may be omitted altogether). The SQL standard uses the notation:

<non-terminal> { [ , <non-terminal> ] }...

to indicate repetition.

The snippet in the question is not directly BNF because it does not use the 'LHS ::= RHS' notation; it effectively assumes the LHS does not need to be named. It also not clear from the notation (as shown - it may be clearer in the original document) whether things like 'CURRENT DATABASE' and 'target_server_name' are terminals or non-terminals (most likely, the current database is a terminal and target server name is not - but BNF would make that clear).

Jonathan Leffler
-1: Jonathan, this isn't really an answer to the question of "what's this syntax called".
John Saunders
+1  A: 

It's an informal, slightly abbreviated form of EBNF:

(http://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_Form)

used in Computer Language Documents at least since the late 60's.

RBarryYoung