I am using the latest Developer Tool within VS2005, accessing a MySQL 5.0 server (on local host). I create a new table in my database, with a field of Type DATETIME, and I want the default value to be set to CURRENT_DATE. When I try to save the table though, I get an error that CURRENT_DATE , which is a mysql function, is not a valid value for my field. Any ideas ?
Regards
Michael
Default Value for DATETIME field
There is a quotation from the MySQL documentation about your problem:
"..The DEFAULT clause specifies a default value for a column. With one exception, 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 as of MySQL 4.1.2.."
"..The DEFAULT clause specifies a default value for a column. With one exception, 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 as of MySQL 4.1.2.."
-
- Posts: 3
- Joined: Tue 03 Feb 2015 02:51
Re: Default Value for DATETIME field
So how can we still accomplish this same task? I have the same issue with a Date column and would like it to automatically input the current date into that field when ever a new record is created.
Re: Default Value for DATETIME field
Could you please describe what exactly you are experiencing issues with as per the previously provided instruction?