This article will discuss several ways to make comments in MySQL. These methods will work if you are using the MySQL shell or editing a .sql file which you will then import into MySQL.
Method 1: Using a ‘#’ to comment until the end of a line
Using a ‘#’ (without the quotes), is a way to comment in a line until the end of the line. This is similar to how you could comment a line in Python.
For example:
select * from bank_table where acc_num='abcd1234'; #bank information
For this method, remember that anything after the ‘#’ wonโt be read. You can continue your code on the next line.
Method 2: Using ‘–‘ to comment until the end of a line
Using ‘–‘ (without the quotes), is a way to comment in a line until the end of the line. This is very similar to method 1.
For example:
select name, age from students where id='S1803393'; -- a student's info
Note: This method might not work in MySQL workbench, but should work in the command line with MySQL.
Method 3: In-line comment
This is using a comment C-style. You can actually write a comment within a line and still continue SQL code after the comment on the same line as opposed to methods 1 and 2. With this method, you start the comment with /* and then end your comment with */
select species /*should be a dog*/ from pet_table where name = 'Cali';
Method 4: Multi-line comments
This is very similar to how you can make multi-line comments in the C language. This is similar to method 3, except you continue it for multiple lines. You start the comment with /*, and then you end the comment with */, the catch is that you could run the comment for as many lines as you want.
For example:
select * from my_table;
/* We should figure out something
more clever to query. This comment is still being continued
This line is where the comment will end. Notice that this comment went on for 3 lines. */
What did you think of this article? Did you have anything to add? Letโs discuss it in the comments below.
๐ Embark on an Epic Time-Travel Adventure with Watson! ๐๐ฆ๐จ
Take a journey through time with Watson the Time-Travelling Dog: Dogs and Dinosaurs Adventure Coloring Book 1.
Join Watson and his dog brother Sherlock as they meet dinosaurs, make new friends, and embark on an unforgettable adventure! Perfect for kids, dog lovers, and coloring book enthusiasts alike.
Why you'll love it:
- Engaging, fun-filled story
- Beautiful illustrations to color
- Ideal for family fun or a thoughtful gift
Ready for an adventure that sparks creativity and fun? ๐ Grab your copy today and let the time-traveling excitement begin!
Get your book now ๐
