2009-04-08

SQL Comments Syntax for Oracle, DB2, MySQL and so on

DBMS Block Comments Line Comments
Oracle /* comments text */ -- comments text
DB2   -- comments text
SQL Server (2000+) /* comments text */ -- comments text
MySQL (4.0+) /* comments text */ -- comments text
# comments text
PostgreSQL /* comments text */ -- comments text


Actually /* */ and -- are SQL standard syntax and have following characteristics.

Block Comments

  • Format : /* comments text */
  • Can be located any position of statement.
  • Can span multiple lines.
  • Can be nested.

Line Comments

  • Format : -- comments text
  • Can start in the middle of line but always extends to the end of line.
  • Can't span multiple lines.
  • Needs at least single space after '--'

1 comment:

  1. Useful post. I find this post very useful as you have shared the complete comment syntax that is used in all the popular databases i.e Oracle, DB2, SQL, MYSQL, PostGreSQL. Thanks for sharing the syntax.
    sap partners

    ReplyDelete