语法定义中使用的特殊符号

时间:2012-06-01 15:29:43

标签: sql syntax

我总是看到sql子句的语法定义如下:

http://msdn.microsoft.com/en-us/library/ms174123.aspx

ALTER TABLE table_name
ALTER COLUMN column_name 
   {
    type_name[({precision[.scale]})][NULL|NOT NULL]
   {DROP DEFAULT 
   | SET DEFAULT constant_expression 
   | IDENTITY [ ( seed , increment ) ]
   } 
| ADD 
   { < column_definition > | < table_constraint > } [ ,...n ] 
| DROP 
   { [ CONSTRAINT ] constraint_name 
   | COLUMN column }
] }
< column_definition > ::= 
   { column_name data_type } 
   [ [ DEFAULT constant_expression ] 
      | IDENTITY [ ( seed , increment ) ] 
   ] 
   [ROWGUIDCOL]
   [ < column_constraint > ] [ ...n ] ]
< column_constraint > ::= 
   [ NULL | NOT NULL ] 
   [ CONSTRAINT constraint_name ] 
   { 
      | { PRIMARY KEY | UNIQUE } 
      | REFERENCES ref_table [ (ref_column) ] 
      [ ON DELETE { CASCADE | NO ACTION | SET DEFAULT |SET NULL } ] 
      [ ON UPDATE { CASCADE | NO ACTION | SET DEFAULT |SET NULL } ]
   }
< table_constraint > ::= 
   [ CONSTRAINT constraint_name ] 
   { [ { PRIMARY KEY | UNIQUE } 
      { ( column [ ,...n ] ) } 
      | FOREIGN KEY 
        ( column [ ,...n ] )
        REFERENCES ref_table [ (ref_column [ ,...n ] ) ] 
      [ ON DELETE { CASCADE | NO ACTION | SET DEFAULT |SET NULL } ] 
      [ ON UPDATE { CASCADE | NO ACTION | SET DEFAULT |SET NULL } ] 
   }

我知道像“|”这样的符号的基本含义,但我可以在哪里得到所有这些符号的完整解释,例如“{”,“[”等?

2 个答案:

答案 0 :(得分:5)

它被称为Backus Naur形式,或者更具体地说是延伸Backus Naur形式,这意味着更具人性化和不太正式。

http://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_Form彻底解决了这个问题。

答案 1 :(得分:2)

  • 管道意味着“或”
  • Curlies表示“可以重复阻止”
  • Squares表示“子句是可选的”
  • Parens是真正的SQL