ujwal kumar singh ujwal kumar singh - 7 months ago 5
SQL Question

how to write create table date query in phpmyadmin which store by default current date if date not given?

I am trying to create a table (phpMyAdmin) by using the following query:

CREATE TABLE login_detail(
Id int(11) primary key auto_increment,
userName varchar(100) not null,
userPassword varchar(100) not null,
created_at Date DEFAULT CURRENT_DATE
);


but it showing error at
CURRENT_DATE
. Can anyone solve this problem?

Answer

Its not supported.

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

http://dev.mysql.com/doc/refman/5.5/en/create-table.html