Menambahkan komentar ke pernyataan SQL

Berlaku untuk:check marked yes Databricks SQL check marked yes Databricks Runtime

Komentar berguna untuk mendokumentasikan kode SQL dan untuk menonaktifkan kode SQL untuk sementara.

Anda dapat menambahkan komentar ke kode SQL sebelum, setelah, dan dalam pernyataan. Komentar diabaikan oleh Azure Databricks kecuali mereka dikenali sebagai petunjuk.

Bentuk komentar berikut didukung:

Komentar sederhana

Komentar sederhana digunakan untuk menutupi seluruh baris teks atau sisa baris teks yang dimulai dengan --

Sintaks

-- text

Parameter

  • text: Teks apa pun yang tidak termasuk karakter akhir baris (EOL) seperti \n.

Contoh

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

Komentar berkurung

Komentar kurung siku digunakan untuk mencakup beberapa baris teks atau sebagian dari baris teks.

Sintaks

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

Parameter

  • text: Teks apa pun termasuk karakter akhir baris (EOL), tidak termasuk /* dan */.

Contoh

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