If the field is in DATE
format, can you do something like auto insert
current date by the muscle as CURRENT_TIMESTAMP
for TIMESTAMP
?
|
2 answers
No, TIMESTAMP is an exception. For other data types, only constants can be used as DEFAULT. See the documentation http://dev.mysql.com/doc/refman/5.5/en/create-table.html
The DEFAULT value sets the default value for a table field with one exception: the default value must be a constant, it cannot be a function or an expression. For example, you cannot set the value of the NOW () or CURRENT_DATE function for a DATE type field. Exception: You can set CURRENT_TIMESTAMP as the default value for a TIMESTAMP type field.
However, there are options:
- Use TIMESTAMP as a data type.
- Make a trigger that implements the required functionality.
|
I propose the following solution:
CONVERT(CURRENT_TIMESTAMP, DATE)
|