![]() | |
![]() |
| | Thread Tools | Display Modes |
#11
| |||
| |||
|
#12
| |||
| |||
|
| DELIMITER ; |
#13
| ||||
| ||||
|
|
So, a trigger's the way go. Found a pretty nice article: http://joegornick.com/2009/12/30/mys...d-date-fields/ Still no luck ![]() |
|
Should be as easy as: -- 1) create the columns ALTER TABLE articles add `date_created` TIMESTAMP NULL DEFAULT NULL; ALTER TABLE articles add `date_modified` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP; |
|
-- 1) create the trigger DROP FUNCTION IF EXISTS temp_before_insert_created_date ; DELIMITER | CREATE TRIGGER temp_before_insert_created_date BEFORE INSERT ON `articles` ^^^^^^^^^^^^^ |
|
FOR EACH ROW BEGIN SET NEW.date_created= CURRENT_TIMESTAMP; END | DELIMITER ; |
#14
| |||
| |||
|
|
So, a trigger's the way go. Found a pretty nice article: http://joegornick.com/2009/12/30/mys...d-date-fields/ Still no luck Should be as easy as:-- 1) create the columns ALTER TABLE articles add `date_created` TIMESTAMP NULL DEFAULT NULL; ALTER TABLE articles add `date_modified` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP; -- 1) create the trigger DROP FUNCTION IF EXISTS temp_before_insert_created_date ; DELIMITER | CREATE TRIGGER temp_before_insert_created_date BEFORE INSERT ON `articles` FOR EACH ROW BEGIN SET NEW.date_created= CURRENT_TIMESTAMP; END | DELIMITER ; New rows get the same date_created and date_modified. Edited rows remain the same. |
![]() |
| Thread Tools | |
| Display Modes | |
| |