MySQL Utility Launches When Modified or Deleted

I had an interesting problem. I would like to create two triggers, trigger1 will fire on DROP TABLE and trigger2 on ALTER TABLE . I would like trigger1 and trigger2 to fire if any table has been deleted or modified, but unfortunately I don’t know the syntax to do this, and I could not find the syntax for such triggers. In MySQL, I can only write triggers that trigger before / after INSERT , UPDATE or DELETE , but now I would like to write triggers that will be applicable at the database level and will trigger table events. Can someone help me?

+4
source share
3 answers

What you are looking for is called "DDL Triggers". MySQL does not support them

There is a SourceForge request , but I'm not sure how seriously someone adds it

+8
source

Cannot use trigger for drop statements. According to the documentation, the trigger is activated on

  • INSERT : the trigger is activated whenever a new row is inserted into the table; for example, through INSERT, LOAD DATA, and REPLACE statements.

    UPDATE : the trigger is activated whenever the line changes; for example, through UPDATE statements.

    DELETE : the trigger is activated whenever a row is deleted from the table; for example, through the DELETE and REPLACE statements. However, the DROP TABLE and TRUNCATE TABLE statements in the table do not activate this trigger because they do not use DELETE.

It does not say anything about the alternate table, but I would expect that only DML statements will be able to fire a trigger.

+1
source
 PROCEDURE `pr_new_type`( IN column_name varchar(10) ) BEGIN SET @queryText = CONCAT('ALTER TABLE `user_rights` ADD ', column_name, ' BINARY( 9 ) NULL'); PREPARE query FROM @queryText; EXECUTE query; DEALLOCATE PREPARE query; END 

check it out

0
source

Source: https://habr.com/ru/post/1388319/


All Articles