If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > CURRENT_DATE as DEFAULT value ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-12-04, 06:02
SamCute SamCute is offline
Registered User
 
Join Date: Mar 2004
Posts: 205
CURRENT_DATE as DEFAULT value ?

Hi,

I couldn't use current_date as default value for a date datatype column in mysql.
How can I acheive this in 'CREATE' statement in mysql.

Thanks,
Sam
Reply With Quote
  #2 (permalink)  
Old 08-12-04, 06:36
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
you can use a timestamp, but unfortunately it will get updated every time the row is updated

otherwise, no, you cannot declare a function as a default value in mysql
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 08-12-04, 15:18
jmut jmut is offline
Registered User
 
Join Date: Mar 2004
Location: Bulgaria
Posts: 22
you could do something like this:
CREATE TABLE X (
last_changed timestamp,
create_time timestamp,
.....);
If you have two columns of type timestamp, only the first one will change on each update. The other one will settle on the date the row was created and stay unchanged.
Hope I've explained that clear.
Reply With Quote
  #4 (permalink)  
Old 08-12-04, 16:17
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by jmut
The other one will settle on the date the row was created and stay unchanged.
nice idea, but how, exactly, does the second one get its initial value?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 08-13-04, 03:57
jmut jmut is offline
Registered User
 
Join Date: Mar 2004
Location: Bulgaria
Posts: 22
Unhappy

Quote:
Originally Posted by r937
nice idea, but how, exactly, does the second one get its initial value?
hmm. unfortunately I'm not sure its possible to be done by default but rather with the insert statement (when the row is first inserted). Sorry.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On