Ga naar inhoud

Header

Comments

Introduction

For various reasons, it can be useful to add comments to code.

For example:

  • For clarification of the code.
  • To indicate what still needs to be done.

Below we see a first example of a comment

SELECT
  -- Select all columns
  *
FROM
  movies
WHERE
  year > 2000
ORDER BY
  rank DESC;




1. Line comments

When you want to place comments in 1 line, use a line comment.

For this, use two dashes:

-- <comment>

See the example below:

SELECT
  -- This is a line comment
  *
FROM
  movies
WHERE
  year > 2000
ORDER BY
  rank DESC;




2. Block comments

When you want to place comments in multiple lines, use a block comment.

For this, use /* to open, and */ to close:

/*
This is a block comment.
It allows comments in multiple lines.
Indeed, multiple lines.
*/

See the example below:

/*
Author:         SQL training
Creation date:  Not so long ago 
Description:    Select data from movies table starting at year 2000
*/
SELECT
  *
FROM
  movies
WHERE
  year > 2000
ORDER BY
  rank DESC;




Summary

  • With comments, you can add commentary to code.
  • Line comments on one line:
    -- This is a line comment
    
  • Block comments on multiple lines:
    /*
    This is a block comment.
    It allows comments in multiple lines.
    Indeed, multiple lines.
    */