MySQL: How to create trigger for setting creation date for new rows

前端 未结 1 1626
伪装坚强ぢ
伪装坚强ぢ 2020-12-28 19:59

I ran into a problem as I tried to create two TIMESTAMP columns in my database. One called created and one called updated. I figured it would be ea

相关标签:
1条回答
  • 2020-12-28 20:34

    Your trigger needs to be "before insert", and you need to use SET instead of UPDATE:

    CREATE TRIGGER task_creation_timestamp BEFORE INSERT ON tasks 
    FOR EACH ROW
    SET NEW.created = NOW();
    
    0 讨论(0)
提交回复
热议问题