Adición de comentarios a instrucciones SQL

Se aplica a:check marked yes Databricks SQL check marked yes Databricks Runtime

Los comentarios son útiles para documentar el código SQL y para deshabilitar temporalmente el código SQL.

Puede agregar comentarios al código SQL antes, después y dentro de las instrucciones. Azure Databricks omite los comentarios a menos que se reconozcan como sugerencias.

Se admiten las siguientes formas de comentarios:

Comentarios simples

Los comentarios simples se usan para cubrir una línea completa de texto o el resto de una línea de texto a partir de --

Sintaxis

-- text

Parámetros

  • text: cualquier texto que excluye un carácter de fin de línea (EOL), como \n.

Ejemplos

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

Comentarios entre corchetes

Los comentarios entre corchetes se usan para cubrir varias líneas de texto o una parte de una línea de texto.

Sintaxis

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

Parámetros

  • text: cualquier texto que incluya caracteres de fin de línea (EOL), excepto /* y */.

Ejemplos

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