last update

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ike

    #1

    last update

    Is there a way in mysql to discern when the last date/time a field, row, or
    table was been updated or inserted? Thanks, ike


  • Gordon Burditt

    #2
    Re: last update

    >Is there a way in mysql to discern when the last date/time a field, row, or[color=blue]
    >table was been updated or inserted? Thanks, ike[/color]

    Maybe, for rows. A timestamp field (well, the first one) is
    automatically set to the current time when the row is modified, or
    when the row is created, UNLESS it is explicitly set to another
    time other than null. So if you handle it properly, you've got a
    row-last-modified-time field. Insert it as null (or leave it out
    of the field list), and don't update it at all. It will be maintained
    for you. But it is easy to fake it by explicitly setting that field
    to something else.

    Table modification times are available with SHOW TABLE STATUS.
    These may be more recent than expected due to things that might not
    be considered modifications, like OPTIMIZE TABLE, which doesn't
    really change any of the data.

    There's no place to store a modification time for every field, and
    no automatic way of updating them, unless you use triggers (available
    in MySQL 5.0). Then you could have an automatically-maintained
    update log (field FOO of table BAR changed from %s to %s at <time>
    by <user>) in another table used to track the changes.

    Gordon L. Burditt

    Comment

    • Ike

      #3
      Re: last update


      "Gordon Burditt" <gordon@hammy.b urditt.org> wrote in message
      news:11ddamm2qb uir85@corp.supe rnews.com...[color=blue][color=green]
      > >Is there a way in mysql to discern when the last date/time a field, row,[/color][/color]
      or[color=blue][color=green]
      > >table was been updated or inserted? Thanks, ike[/color]
      >
      > Maybe, for rows. A timestamp field (well, the first one) is
      > automatically set to the current time when the row is modified, or
      > when the row is created, UNLESS it is explicitly set to another
      > time other than null. So if you handle it properly, you've got a
      > row-last-modified-time field. Insert it as null (or leave it out
      > of the field list), and don't update it at all. It will be maintained
      > for you. But it is easy to fake it by explicitly setting that field
      > to something else.[/color]

      How would you access that value Gordon? Thanks, Ike


      Comment

      • Ike

        #4
        Re: last update


        "Ike" <rxv@hotmail.co m> wrote in message
        news:6ZLBe.3841 $dU3.1958@newsr ead2.news.pas.e arthlink.net...[color=blue]
        >
        > How would you access that value Gordon? Thanks, Ike
        >[/color]

        Whoops, my mistake - I assumed MySQL kept a value for that outside your own
        table. I see now that you meant adding a TIMESTAMP field to the table.
        Thanks again, Ike


        Comment

        • Gordon Burditt

          #5
          Re: last update

          >> >Is there a way in mysql to discern when the last date/time a field, row,[color=blue]
          >or[color=green][color=darkred]
          >> >table was been updated or inserted? Thanks, ike[/color]
          >>
          >> Maybe, for rows. A timestamp field (well, the first one) is
          >> automatically set to the current time when the row is modified, or
          >> when the row is created, UNLESS it is explicitly set to another
          >> time other than null. So if you handle it properly, you've got a
          >> row-last-modified-time field. Insert it as null (or leave it out
          >> of the field list), and don't update it at all. It will be maintained
          >> for you. But it is easy to fake it by explicitly setting that field
          >> to something else.[/color]
          >
          >How would you access that value Gordon? Thanks, Ike[/color]

          With a SELECT, just like any other field.

          YOU have to put that field in the table; it's not a magic field
          with a magic name that's always there.

          Gordon L. Burditt

          Comment

          Working...