MySQL datetime default time with interval

前端 未结 2 1224
星月不相逢
星月不相逢 2021-01-06 20:33

Is it possible to add to a default time with NOW(), 10 minutes?

I\'ve tried something like that:

CREATE TABLE `table1` (
    `date` DATETIME NOT NULL         


        
2条回答
  •  情书的邮戳
    2021-01-06 20:47

    You could however use an insert-trigger to accomplish this. Set the default for the 'date' column to null, and use

    CREATE TRIGGER settime
    BEFORE INSERT on table1
    FOR EACH ROW BEGIN
        IF new.`date` is null THEN
            SET new.`date` = DATE_ADD(NOW(), INTERVAL 10 MINUTE);
        END IF;
    END;
    

提交回复
热议问题