Adding comments to SQL statements
Applies to: Databricks SQL Databricks Runtime
Comments are useful for documenting SQL code and for temporarily disabling SQL code.
You can add comments to SQL code before, after, and within statements. Comments are ignored by Azure Databricks unless they are recognized as hints.
The following forms of comments are supported:
Simple comments
Simple comments are used to cover an entire line of text or the remainder of a line of text starting with --
Syntax
-- text
Parameters
text
: Any text excluding an end-of-line (EOL) character such as\n
.
Examples
> -- 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 comments
Bracketed comments are used to cover multiple lines of text or a portion of a line of text.
Syntax
bracketed_comment
/* text [ bracketed_comment [...] ] text */
Parameters
text
: Any text including end-of-line (EOL) characters, excluding/*
and*/
.
Examples
> /* 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 */