SQL 注释符号示例

这些示例说明了使用 SQL 注释指示符的不同方式。

以下示例使用了每一种注释符号,包括双连字符(--)、花括号({ })、C 语言样式(/* . . . */)的注释符号在 SQL 语句后注释。该注释与语句显示在同一行。
SELECT * FROM customer; -- Selects all columns and rows
          
          SELECT * FROM customer; {Selects all columns and rows}
          
          SELECT * FROM customer; /*Selects all columns and rows*/
以下三个示例与前面的示例使用了相同的 SQL 语句和相同的注释,但注释自成一行:
SELECT * FROM customer; 
          -- Selects all columns and rows
          
          SELECT * FROM customer; 
          {Selects all columns and rows}
          
          SELECT * FROM customer; 
          /*Selects all columns and rows*/
以下示例中,用户输入与前面的示例中相同的 SQL 语句,但现在输入一条多行注释(或者对于双连字符有两条注释):
SELECT * FROM customer;
          -- Selects all columns and rows
          -- from the customer table
          
          SELECT * FROM customer;
          {Selects all columns and rows
          from the customer table}
          
          SELECT * FROM customer;
          /*Selects all columns and rows
          from the customer table*/
一条 SQL 语句中出现任意三种样式的注释:
SELECT *           -- Selects all columns and rows
          FROM customer;  -- from the customer table
          
          SELECT *           {Selects all columns and rows}
          FROM customer;  {from the customer table}
          
          SELECT *           /*Selects all columns and rows*/
          FROM customer;  /*from the customer table*/
        
如果您使用花括号或 C 语言样式的注释被成对的开始和结束符号定界,那么结束注释符号必须与开始注释符号的样式相同。