php - Mysql date created (not to update when record updated) -
i'm doing mysql table , have 1 column has current timestamp on update. great because can see when uploads something. dont want column change when edit upload. best stick 1 column named "date created" , have no on update or go 2 columns "date created & "date modified" - if whats best practice column attributes, , php update statements?
i have separate "createdate" , "lastmodifieddate".
as setting it, nice if set default value createdate column now()
, mysql doesn't allow that.
so, easiest option use insert trigger it:
create trigger tbl_insert before insert on `tbl` each row set new.createdate = now(), new.lastmodifieddate = now();
eta:
you can use timestamp
field default value of current_timestamp
, on update current_timestamp
constraint lastmodifieddate well. unfortunately can't have 2 such timestamp
columns on same table, trigger necessary handle createdate column.
Comments
Post a Comment