How to comment stored procedure in MySQL
34,227
Solution 1
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:
Solution 2
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.
Comments
-
John Christy about 2 years
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.
-
Henrik Erlandsson about 5 yearsThat <space> is a huge gotcha. Devs don't need that, or the generic "there's some sort of syntax error somewhere near something in your code".