Skip to content

Instantly share code, notes, and snippets.

@balda
Last active January 2, 2016 18:19
Show Gist options
  • Save balda/8342586 to your computer and use it in GitHub Desktop.
Save balda/8342586 to your computer and use it in GitHub Desktop.
Add date insert and date update fields.
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 ;
@balda
Copy link
Author

balda commented Jan 9, 2014

To use it, remplace [[_TABLE_]] by table name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment