Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to comment stored procedure in MySQL

I am trying to comment a stored procedure using MySQL workbench. I tried with the following syntax -

/**
Hai
*/  

and

-- hai

These two will execute perfectly but changes never gets updated to stored procedure, while opening stored procedure it does not show any changes.

Thanks for any help.

like image 916
John Christy Avatar asked Dec 19 '12 09:12

John Christy


People also ask

How do I comment in a stored procedure?

To create line comments you just use two dashes "--" in front of the code you want to comment. You can comment out one or multiple lines with this technique. In this example the entire line is commented out.

What is /* in MySQL?

This is a type of comment. The /* is the beginning of a comment and */ is the end of comment. MySQL will ignore the above comment.

How do you comment multiple lines in MySQL?

Multi-line comments start with /* and end with */ . Any text between /* and */ will be ignored.

How do I comment out a line in SQL Workbench?

This worked on MySQL Workbench 8.0. 16 (Windows 10), Thank You. (Pressing Fn + Ctrl + / while a block of code is selected will comment/un-comment the block as expected.


2 Answers

You should place your comments inside the procedure body, i.e., what's between BEGIN and END. The rest of the code are instructions to create the procedure and are lost once you run them.

Comment syntax is as usual:

  • /* ... */
  • --<space>

MySQL Workbench conveniently warns about this:

enter image description here

like image 93
Álvaro González Avatar answered Sep 24 '22 14:09

Álvaro González


MySQL has a comment feature. Official manual here.

Example:

DELIMITER $$
CREATE PROCEDURE proc_name()
COMMENT 'this is my comment'
BEGIN
/*here comes my voodoo*/
END $$
DELIMITER ;

This way you also save the comment in the database, not just in your source code.

like image 36
fancyPants Avatar answered Sep 25 '22 14:09

fancyPants