SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: update problem

  1. #1
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    update problem

    Hi,

    I am updating a record in a table and have a problem with current timestamp as the default setting for a column.

    what am I doing wrong please?

    Code MySQL:
    UPDATE booked
               SET actual_occupancy = ?, 
                   room_status = ?,  
                   date_of_booking = 'default'           
               WHERE id = ?
    It seems that if I only update the first two cols shown, the value of current timestamp is not updated. How can I get it to update and therefore show the time when the record was last updated
    bazz

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Code:
    UPDATE booked
               SET actual_occupancy = ?, 
                   room_status = ?,  
                   date_of_booking = CURRENT_TIMESTAMP    
               WHERE id = ?

  3. #3
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you Dan.

    I am curious though, as to why I need to enter TIMESTAMP when that value is already set as the default. Maybe it's just as simple as that is the only way to do it.

    bazz

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The manual explains all the various behaviors a TIMESTAMP column shows depending on your DEFAULT and ON UPDATE clauses in the CREATE TABLE statement.

    http://dev.mysql.com/doc/refman/5.0/en/timestamp.html

    A DEFAULT value of CURRENT_TIMESTAMP does not update the column when a row is updated, and settings it value to the string 'default' doesn't seem to appear anywhere as having some special effect.


Bookmarks

Posting Permissions

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