Comments are used to explain sections of SQL statements, or to prevent execution of SQL statements.
Comments are ignored by the database engine. They are for human readers to better understand the purpose of the code.
Single line comments start with --.
Any text between -- and the end of the line will be ignored (will not be executed).
-- Select all customers from Germany SELECT * FROM Customers WHERE Country = 'Germany';
You can also place a single line comment at the end of a line:
SELECT * FROM Customers -- WHERE Country = 'Germany';
In this example, the WHERE clause is commented out and will not be executed.
Multi-line comments start with /* and end with */.
Any text between /* and */ will be ignored.
/* Select all customers. This is a multi-line comment used to explain the query. */ SELECT * FROM Customers;
You can also use multi-line comments to disable parts of a statement:
SELECT CustomerName, /* City, */ Country FROM Customers;
Here, the City column will not be included in the result set.