I was reading these articles on StackOverflow regarding triggers and created date and updated date in mysql, and was wondering whether it is possible to create a trigger that checks if these two fields are present in the create table statement, and either creates the relevant trigger, or creates the fields, as well as the trigger? I am aware that there will be some tables for which this is not relevant, but I will address that in the future.

What is the best way to set up last-modified and date-record-added fields?

adding column to all tables in a mysql database (unknown table names)


The feature you are asking for is called "DDL triggers".

And no, MySQL doesn't have that. So you can't do this in a trigger.

  • So I will have to make sure to add the triggers manually. Thank you. Do you know if mariadb or postgresql have the feature? – JoSSte Mar 12 '17 at 15:07
  • Postgres has Event triggers - implemented in 9.3 - but I've never used that feature. – ypercubeᵀᴹ Mar 12 '17 at 15:14
  • @JoSSte , also - each tasks have many ways for realisation, main question - what the goals? Why You need create this? As example - MariaDB have excellent Audit Plugin (compatible with any MySQL) - it allow You audit all DDL changes, You can parse them and use this information. – a_vlad Mar 12 '17 at 21:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.