2013-09-27 48 views
1

在MSDN Library或Technet網站上,Microsoft傾向於使用僞語法來解釋如何在所有可用選項中使用T-SQL語句。下面是一個示例從TechNet頁面的承擔UPDATE STATISTICS如何正確讀取SQL Server語法?

UPDATE STATISTICS table_or_indexed_view_name 
    [ 
     { 
      { index_or_statistics__name } 
      | ({ index_or_statistics_name } [ ,...n ]) 
       } 
    ] 
    [ WITH 
     [ 
      FULLSCAN 
      | SAMPLE number { PERCENT | ROWS } 
      | RESAMPLE 
      | <update_stats_stream_option> [ ,...n ] 
     ] 
     [ [ , ] [ ALL | COLUMNS | INDEX ] 
     [ [ , ] NORECOMPUTE ] 
    ] ; 

<update_stats_stream_option> ::= 
    [ STATS_STREAM = stats_stream ] 
    [ ROWCOUNT = numeric_constant ] 
    [ PAGECOUNT = numeric_contant ] 

如何正確讀取這樣的描述,迅速找出需要什麼,哪些是可選的,清潔的方式來編寫你的查詢?

+1

一切[]是可選 –

回答

3

你應該參考這個Transact-SQL Syntax Conventions

該文章中的第一個表解釋幾乎一切。

在您的例子中,我們可以看到如下:

UPDATE STATISTICS table_or_indexed_view_name 

UPDATE STATISTICS是用於 關鍵字table_or_indexed_view_name是表的名稱或更新

[ 
    { 
     { index_or_statistics__name } 
     | ({ index_or_statistics_name } [ ,...n ]) 
      } 
] 

這是統計視圖可選[],但如果提供,則必須輸入統計名稱{index_or_statistics__name}|統計名稱列表,用逗號分隔{ index_or_statistics_name } [ ,...n ]

[ WITH 
    [ 
     FULLSCAN 
     | SAMPLE number { PERCENT | ROWS } 
     | RESAMPLE 
     | <update_stats_stream_option> [ ,...n ] 
    ] 
    [ [ , ] [ ALL | COLUMNS | INDEX ] 
    [ [ , ] NORECOMPUTE ] 
] ; 

這也是可選[]。如果使用,則必須以WITH開頭,並且您有4個選項,您必須從中選擇。 您的選項是

  1. FULLSCAN
  2. SAMPLE number { PERCENT | ROWS },在那裏你必須定義number,你必須選擇從PERCENT|ROWS
  3. RESAMPLE
  4. `[,... n]的」,這是以逗號分隔的列表

然後,您必須選擇ALL,COLUMNSINDEX並用逗號主持,如果您使用了WITH

最後,如果您之前使用過任何其他選項,則可以使用另一個選項來使用NORECOMPUTE並在其之前放置逗號。

<update_stats_stream_option> ::= 
[ STATS_STREAM = stats_stream ] 
[ ROWCOUNT = numeric_constant ] 
[ PAGECOUNT = numeric_contant ] 

這些預定義的選項列表,你可以使用其中<update_stats_stream_option>之前使用(4)。

3

方括號[...]之間的任何事情都是可選的

由管道分隔的任何事情|符號是一個或另一個選項。

在你上面的例子中,你可以把它讀作在方括號

UPDATE STATISTICS table_or_indexed_view_name 
[ optionally specify an index as well] 
[ optionally specify options using **WITH** 

     If you use WITH then you can follow it with one of the following keywords 
     FULLSCAN 
     OR SAMPLE number { PERCENT | ROWS } 
     OR RESAMPLE 
].. and so on