Add a comment (description) to the trigger

If I create a trigger with syntax CREATE TRIGGERin MySQL, how can I attach a comment to it that describes it? I mean in the declaration or after it the same for me.

I can not understand. With tables you add COMMENT = 'Wonderful table with users inside';at the end of the ad. But how to add comments to the trigger?

+5
source share
4 answers

You cannot attach a comment to a trigger.

However, you can add comments to the trigger body.

If you enter comments in the body, for example, /** comment **/
you can extract these comments with the following query:

SELECT
  SUBSTRING(b.body, b.start, (b.eind - b.start)) as comment 
FROM (
  SELECT
    a.body 
    ,locate('/**',a.body) as start
    ,locate('**/',a.body) as eind
  FROM (
    SELECT t.ACTION_STATEMENT as body FROM information_schema.triggers t 
    WHERE t.TRIGGER_NAME like %aname% 
  ) a
) b
+4
source

, . -

CREATE TRIGGER trigger1
AFTER INSERT
ON table1
FOR EACH ROW
BEGIN
  -- 'Wonderful trigger with insert inside';
  INSERT INTO table2 VALUES(NEW.id);
END
+4

mysql -

CREATE TRIGGER trigger1
AFTER INSERT
ON table1
FOR EACH ROW
BEGIN
  /*!99999 This is my comment , i will ignore at run time. */
  INSERT INTO table2 VALUES(NEW.id);
END

To prevent the execution of "code", you can simply use a very high version number, for example 99999.

+1
source

You can also use

#"your comment" he works like //"your comment"

in other languages, for example: C, C ++, PHP, etc.

0
source

All Articles