I was thinking at something like this:
`post_modified` int(11) NOT NULL DEFAULT UNIX_TIMESTAMP (NOW ()) ON UPDATE UNIX_TIMESTAMP (NOW ()),
But this code it is not working.
Note : I have no idea about the performance of MYSQL TRIGGER
Please go through these links
You can create triggers for this.
for insertion
CREATE TRIGGER {trigger_name} BEFORE INSERT ON {table_name} FOR EACH ROW SET new.{field_name} = UNIX_TIMESTAMP(NOW());
for update
CREATE TRIGGER {trigger_name} BEFORE UPDATE ON {table_name} FOR EACH ROW SET new.{field_name} = UNIX_TIMESTAMP(NOW());
Nope you cant use it as you showed.
From Data Type doc on MySql:
"The default value must be a constant; it cannot be a function or an expression. This means, for example, that you cannot set the default for a date column to be the value of a function such as NOW() or CURRENT_DATE. The exception is that you can specify CURRENT_TIMESTAMP as the default for a TIMESTAMP column."
Look at below answer for workaround:
Is it possible to create a column with a UNIX_TIMESTAMP default in MySQL?
Hope this will help !
timestamp
fields. You'll have to use a trigger to set a unix timestamp.