SQL comments
In most host languages, static SQL statements can include host language or SQL comments. In Java™ and REXX, static SQL statements cannot include host language or SQL comments.
Dynamic SQL statements can include SQL comments.
There are two types of SQL comments:
- simple comments
- Simple comments are introduced by two consecutive hyphens.
- bracketed comments
- Bracketed comments are introduced by /* and end with */.
These 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 wherever 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 hyphens must be preceded by a space.
These 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.
A comment embedded in an SQL statement that precedes a name (such as a table name) may cause object names in the text saved for a view, trigger, variable, or MQT to not be maintained correctly. Similarly, names in rows of a dependency view (such as SYSTRIGDEP) may not be correctly qualified.
Example 1
This example shows how to include simple comments in a statement:
CREATE VIEW PRJ_MAXPER -- PROJECTS WITH MOST SUPPORT PERSONNEL
AS SELECT PROJNO, PROJNAME -- NUMBER AND NAME OF PROJECT
FROM PROJECT
WHERE DEPTNO = 'E21' -- SYSTEMS SUPPORT DEPT CODE
AND PRSTAFF > 1
Example 2
This example shows how to include bracketed comments in a statement:
CREATE VIEW PRJ_MAXPER /* PROJECTS WITH MOST SUPPORT
PERSONNEL */
AS SELECT PROJNO, PROJNAME /* NUMBER AND NAME OF PROJECT */
FROM PROJECT
WHERE DEPTNO = 'E21' /* SYSTEMS SUPPORT DEPT CODE */
AND PRSTAFF > 1