Comments | SQL Fundamentals | Teradata Vantage - Comments - Advanced SQL Engine - Teradata Database

SQL Fundamentals

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-24
dita:mapPath
zwv1557098532464.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1141
lifecycle
previous
Product Category
Teradata Vantageâ„¢

You can embed comments within an SQL request anywhere a pad character can occur.

The SQL Parser and the preprocessor recognize the following types of ANSI/ISO SQL:2011-compliant embedded comments:
  • Simple
  • Bracketed

Simple Comments

The simple form of a comment is delimited by two consecutive HYPHEN-MINUS (U+002D) characters (--) at the beginning of the comment and the newline character at the end of the comment.

-- comment_text new_line_character

The newline character is implementation-specific, but is typed by pressing the Enter (non-3270 terminals) or Return (3270 terminals) key.

Simple SQL comments cannot span multiple lines.

Example: Using a Simple Comment at the End of a Line

The following examples illustrate the use of a simple comment at the end of a line, at the beginning of a line, and at the beginning of a statement:

SELECT EmpNo, Name FROM Payroll_Test
ORDER BY Name -- Simple comment at the end of a line
;
SELECT EmpNo, Name FROM Payroll_Test
-- Simple comment at the beginning of a line
ORDER BY Name;
-- Simple comment at the beginning of a statement
SELECT EmpNo, Name FROM Payroll_Test
ORDER BY Name;

Bracketed Comments

A bracketed comment is a text string of unrestricted length that is delimited by the beginning comment characters SOLIDUS (U+002F) and ASTERISK (U+002A) /* and the end comment characters ASTERISK and SOLIDUS */.

/* comment_text */

Bracketed comments can begin anywhere on an input line and can span multiple lines.

Example: Using a Bracketed Comment at the Beginning, Middle and End of a Line

The following examples illustrate the use of a bracketed comment at the end of a line, in the middle of a line, at the beginning of a line, and at the beginning of a statement:

SELECT EmpNo, Name FROM Payroll_Test /* This bracketed comment starts
                                        at the end of a line
                                        and spans multiple lines. */
ORDER BY Name;
SELECT EmpNo, Name FROM Payroll_Test
/* This bracketed comment starts
   at the beginning of a line
   and spans multiple lines. */
ORDER BY Name;
/* This bracketed comment starts
   at the beginning of a statement
   and spans multiple lines. */
SELECT EmpNo, Name FROM Payroll_Test
ORDER BY Name;
SELECT EmpNo, Name
FROM  /* This comment is in the middle of a line. */ Payroll_Test
ORDER BY Name;
SELECT EmpNo, Name FROM Payroll_Test /* This bracketed
   comment starts at the end of a line, spans multiple
   lines, and ends in the middle of a line. */ ORDER BY Name;
SELECT EmpNo, Name FROM Payroll_Test
/* This bracketed comment starts at the beginning of a line,
   spans multiple lines, and ends in the
   middle of a line. */ ORDER BY Name;

Comments With Multibyte Character Set Strings

You can include multibyte character set strings in both simple and bracketed comments.

When using mixed mode in comments, you must have a properly formed mixed mode string, which means that a Shift-In (SI) must follow its associated Shift-Out (SO).

If an SI does not follow the multibyte string, the results are unpredictable.

When using bracketed comments that span multiple lines, the SI must be on the same line as its associated SO. If the SI and SO are not on the same line, the results are unpredictable.

You must specify the bracketed comment delimiters (/* and */) as single byte characters.