SQL comments

Static SQL statements can include host language or SQL comments. Dynamic SQL statements can include SQL comments. There are two types of SQL comments, simple comments and bracketed comments.

simple comments
Simple comments are introduced with two consecutive hyphens (--) and end with the end of a line. The following rules apply to the use of simple comments:
  • The two hyphens must be on the same line and must not be separated by a space.
  • Simple comments can be started whenever a space is valid (except within a delimiter token or between 'EXEC' and 'SQL').
  • Simple comments cannot be continued to the next line.
  • In COBOL, the hyphen must be preceded by a space.
bracketed comments
Bracketed comments are introduced with /* and end with */. The following rules apply to the use of bracketed comments:
  • The /* must be on the same line and not separated by a space.
  • The */ must be on the same line and not separated by a space.
  • Bracketed comments can be started wherever a space is valid (except within a delimiter token or between 'EXEC' and 'SQL').
  • Bracketed comments can be continued to the next line.
  • Bracketed comments can be nested within other bracketed comments. However, nested bracketed comments are not supported by DSNTEP2, DSNTEP4, SPUFI, or the command line processor.
  • Bracketed comments are not allowed in static SQL statements in a COBOL, Fortran, or Assembler program.
Example: This example shows how to include comments in an SQL statement within a C program. The example uses both simple and bracketed comments:
   EXEC SQL
     CREATE VIEW PRJ_MAXPER         --projects with most support personnel
       /*
        * Returns number and name of the project
        */
      AS SELECT PROJNO, PROJNAME     -- number and name of project
           FROM DSN8910.PROJ
        /*
         * E21 is the systems support dept code
         */
      WHERE DEPTNO = 'E21'           -- systems support dept code
      AND PRSTAFF > 1;

For information about host language comments, refer to DB2 Application Programming and SQL Guide.