Last Updated: 24 June, 2023
In MySQL, comments are used to add explanatory or descriptive notes within SQL statements or stored procedures. Comments do not affect the execution of the SQL code and are ignored by the MySQL server.
There are two types of comments in MySQL:
Single-line comments: Single-line comments start with two consecutive hyphens (--). Anything written after the hyphens on the same line is considered a comment and is ignored by the MySQL server.
For example:
SELECT * FROM customers; -- This is a single-line comment
Multi-line comments: Multi-line comments start with a forward slash and an asterisk (/) and end with an asterisk and a forward slash (/). Anything written between these delimiters is considered a comment and is ignored by the MySQL server. Multi-line comments can span across multiple lines.
For example:
/* This is a multi-line comment It can span across multiple lines */ SELECT * FROM orders;
Comments are commonly used for various purposes, including:
It's good practice to use comments in our SQL code to improve its readability and maintainability, as well as to help others understand our code.
That's all, guys. I hope this MySQL article is helpful for you.
Happy Learning... 😀
feedback@javabytechie.com