Setting Default Value in Mysql Datetime Column

As you know MySQL datetime column does not accept functions as default values. The workaround is to use triggers. This trigger updates the datetime value to NOW(). This is how it is done:

DELIMITER $$

CREATE
    /*[DEFINER = { user | CURRENT_USER }]*/
    TRIGGER `DatabaseName`.`TriggerName` BEFORE INSERT
    ON `TableName`.`TableName`
    FOR EACH ROW BEGIN
                SET NEW.ColumnName=NOW();user_quizes
    END$$

DELIMITER ;

Categories

Archive