Lägga till kommentarer i SQL-instruktioner

Gäller för:check marked yes Databricks SQL check marked yes Databricks Runtime

Kommentarer är användbara för att dokumentera SQL-kod och för att tillfälligt inaktivera SQL-kod.

Du kan lägga till kommentarer i SQL-kod före, efter och inom -instruktioner. Kommentarer ignoreras av Azure Databricks om de inte identifieras som tips.

Följande typer av kommentarer stöds:

Enkla kommentarer

Enkla kommentarer används för att täcka en hel textrad eller resten av en textrad som börjar med --

Syntax

-- text

Parametrar

  • text: All text exklusive ett EOL-tecken (end-of-line), till exempel \n.

Exempel

> -- 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

Kommentarer inom hakparentes

Hakparenteserade kommentarer används för att täcka flera textrader eller en del av en textrad.

Syntax

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

Parametrar

  • text: All text inklusive EOL-tecken (end-of-line), exklusive /* och */.

Exempel

> /* 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 */