Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Add default value for date field
Hello all

I have a field (called active) of type DATE and I want to add a default
value. The default value must be the current date. Is this possible to do
this in the table create statement?

CREATE TABLE mytable
(
id INTEGER NOT NULL AUTO_INCREMENT,
active DATE DEFAULT ?????,
PRIMARY KEY (id),
)

Thanks in advance
Roger




Report this thread to moderator Post Follow-up to this message
Old Post
Rob
05-11-05 08:58 PM


Re: Add default value for date field
I think it's impossible, you have to insert the date each time you write
into your DB. Cf. MySQL Ref Manual:

"
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. See Section 11.3.1.2, "TIMESTAMP
Properties as of MySQL 4.1".

"

++

"Rob" <reply@newsgroup.nl> a écrit dans le message de news:
d5t77g$drf$1@reader10.wxs.nl...
> Hello all
>
> I have a field (called active) of type DATE and I want to add a default
> value. The default value must be the current date. Is this possible to do
> this in the table create statement?
>
> CREATE TABLE mytable
>   (
>    id INTEGER NOT NULL AUTO_INCREMENT,
>    active DATE DEFAULT ?????,
>    PRIMARY KEY (id),
>   )
>
> Thanks in advance
> Roger
>
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
VAUTHIER Christophe
05-11-05 08:58 PM


Re: Add default value for date field
On Wed, 11 May 2005 18:09:46 +0200, "VAUTHIER Christophe"
<crashbronx@wanadoo.fr> wrote:

>I think it's impossible, you have to insert the date each time you write
>into your DB. Cf. MySQL Ref Manual:
>
>"
> 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. See Section 11.3.1.2, "TIMESTAMP
>Properties as of MySQL 4.1".
>
>"
>
>++
>
>"Rob" <reply@newsgroup.nl> a écrit dans le message de news:
>d5t77g$drf$1@reader10.wxs.nl... 
>
No.
In your insert Query, use the pair of     active    and     curdate()

Report this thread to moderator Post Follow-up to this message
Old Post
tim
05-14-05 08:59 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP SQL archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 09:31 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.