Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2004
    Posts
    205

    Unanswered: 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

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    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.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •