共用方式為


新增註解至 SQL 語句

適用於:勾選是Databricks SQL 勾選是Databricks Runtime

批註適用於記錄 SQL 程式代碼,以及暫時停用 SQL 程式代碼。

您可以在 語句之前、之後和內新增批注至 SQL 程式代碼。 除非將其辨識為 提示,否則 Azure Databricks 會忽略批註。

支援下列形式的批註:

簡單批注

簡單的批注可用來涵蓋整行文字,或涵蓋從--開始直至行尾的文字部分。

語法

-- text

參數

  • text:任何不包含行尾字元的文字,例如 \n

範例

> -- This is a comment

> SELECT 1; -- This is also a comment
  1

> SELECT -- This is a comment
 1;
  1

> SELECT -- Comments are not limited to Latin characters: 评论 😊
 1;
  1

> SELECT '-- This is not a comment';
  -- This is not a comment

> SELECT -- This is a bad comment because the "one" should be on the next line... 1
 Syntax error

> SELECT -- this is a bad
comment because it contains an EOL character
  1;
 Syntax error

括號批注

括號批注可用來涵蓋多行文字或文字行的一部分。

語法

bracketed_comment
  /* text [ bracketed_comment [...] ] text */

參數

  • text:包括行尾字元(EOL)的任何文字,但不包括 /**/

範例

> /* This is a comment */

> SELECT 1; /* This is also a comment */

> SELECT /* This is a comment
  that spans multiple lines */ 1;

> SELECT /* Comments are not limited to Latin characters: 评论 😊 */ 1;

> SELECT /* Comments /* can be */ nested */ 1;

> SELECT /* Quotes in '/*' comments "/*" are not special */ */ */ 1;

> /* A prefixed comment */ SELECT 1;

> SELECT '/* This is not a comment */';
  /* This is not a comment */