Last active
January 2, 2016 18:19
-
-
Save balda/8342586 to your computer and use it in GitHub Desktop.
Add date insert and date update fields.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALTER TABLE `[[_TABLE_]]` ADD `date_insert` DATETIME NOT NULL , ADD INDEX ( `date_insert` ) ; | |
ALTER TABLE `[[_TABLE_]]` ADD `date_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP , ADD INDEX ( `date_update` ) ; | |
DROP TRIGGER IF EXISTS `Trigger_DateInsert_[[_TABLE_]]`; | |
DELIMITER // | |
CREATE TRIGGER `Trigger_DateInsert_[[_TABLE_]]` BEFORE INSERT ON `[[_TABLE_]]` | |
FOR EACH ROW BEGIN | |
SET NEW.`date_insert` = NOW(); | |
END | |
// | |
DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use it, remplace
[[_TABLE_]]
by table name.