Aggiunta di commenti alle istruzioni SQL

Si applica a:check marked yes Databricks SQL check marked yes Databricks Runtime

I commenti sono utili per documentare il codice SQL e per disabilitare temporaneamente il codice SQL.

È possibile aggiungere commenti al codice SQL prima, dopo e all'interno delle istruzioni. I commenti vengono ignorati da Azure Databricks, a meno che non vengano riconosciuti come hint.

Sono supportati i seguenti tipi di commenti:

Commenti semplici

I commenti semplici vengono usati per coprire un'intera riga di testo o il resto di una riga di testo che inizia con --

Sintassi

-- text

Parametri

  • text: qualsiasi testo escluso un carattere di fine riga (EOL), ad esempio \n.

Esempi

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

Commenti tra parentesi quadre

I commenti tra parentesi quadre vengono usati per coprire più righe di testo o una parte di una riga di testo.

Sintassi

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

Parametri

  • text: qualsiasi testo incluso i caratteri end-of-line (EOL), escluso /* e */.

Esempi

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