📅  最后修改于: 2020-11-12 00:37:14             🧑  作者: Mango
SQL注释用于解释SQL语句的各个部分,并用于防止SQL语句。在许多编程语言中,注释非常重要。
Microsoft Access数据库不支持注释。因此,Mozilla Firefox和Microsoft Edge在示例中使用Microsoft Access数据库。
共有三种类型的注释,如下所示:
以单行开头和结尾的注释称为单独的行注释。以“ –”开头的行是单行注释,并且不执行该特定行。
-和行尾之间的文本将被忽略,无法执行。
句法:
下面的示例使用单行注释:
--Select all:
SELECT * FROM Employees;
给定的示例使用单行注释来忽略行尾:
SELECT * FROM Customers -- WHERE City='London';
以下示例使用单行注释忽略语句:
--SELECT * FROM Employees;
SELECT * FROM Products;________________________________________________________________________________
以一行开始并以不同的开头结束的注释称为多行注释。 / *和* /之间的文本在代码部分中被忽略。
以“ / *”开头的行被视为注释的起点,当“ * /”位于末尾时终止。
句法:
/* multi-line comment
another comment */
SELECT * FROM Customers;
/*Select all the columns
of all the records
in the Customers table:*/
SELECT * FROM Employees;
下面的示例使用多行注释来忽略更多语句:
/*SELECT * FROM Customers;
SELECT * FROM Products;
SELECT * FROM Orders;
SELECT * FROM Categories;*/
SELECT * FROM Suppliers;
要忽略语句的某些部分,请使用/ * ……. * /注释。
以下示例使用注释忽略任何代码的某些部分:
/*SELECT * FROM Customers;
SELECT * FROM Products;
SELECT * FROM Orders;
SELECT * FROM Categories;*/
SELECT * FROM Suppliers;
SELECT CustomerName, /*City,*/ Country FROM Customers;
下面的示例使用注释不成为语句的一部分:
SELECT * FROM Customers WHERE (CustomerName LIKE 'L%.'
OR CustomerName LIKE 'R%' /*OR CustomerName LIKE 'S%'
OR CustomerName LIKE 'T%'*/ OR CustomerName LIKE 'W%')
AND Country='America.'
ORDER BY CustomerName;
内联注释是多行注释的扩展,注释可以在语句之间声明,并包含在“ / *”和“ * /”之间。
句法:
选择* FROM / *雇员; * /
Multi line comment ->
/* SELECT * FROM Teachers;
SELECT * FROM Teacher_DETAILS;
SELECT * FROM Orders; */
SELECT * FROM Course;
在线评论->
SELECT * FROM Students;
SELECT * FROM /* Employee_DETAILS;
SELECT * FROM Orders;
SELECT * FROM */ Topics;
根据给定的示例指示SQL Comment Indicator
它包括双连字符(—),花括号({})和C样式(/ *。。。* /)注释定界符。声明后还包括评论。
SELECT * FROM customer; -- Selects all rows and columns
SELECT * FROM employee; {Selects all rows and columns}
SELECT * FROM employee; /*Selects all columns and rows*/copy to the clipboard
在以下示例中,我们将注释放在一行代码上-
SELECT * FROM customer;
-- Selects all the rows and columns
SELECT * FROM employee;
{Selects all columns and rows}
SELECT * FROM customer;
/*Selects all columns and rows*/
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*/copy to clipboard
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*/copy to clipboard