locked
how to check the last timestamp value and current one RRS feed

  • Question

  • I have a row with 2 columns.
     one - int datatype
    second - timstamp datatype


    for the first time I have inserted a value in one column,now let me say the row as value(1,0x0000000000000BB9)
    I just updated the value 1 as 2 and the row now becomes (2,0x0000000000000FA1)

    how to get the previous timestamp  value (0x0000000000000BB9) and current one?

    In short if a row is updated, how to check whether the row is updated through timestamp datatype?

    Thanks, Bharathi
    Thursday, September 17, 2009 7:08 AM

Answers

  • create table #test
    (
        one        int,
        [second]    timestamp
    )
    
    insert into #test (one)
    select    1
    
    select    * from #test
    
    update    t
    set    one     = one + 1
    OUTPUT    deleted.second as previous, inserted.second as [current]
    from    #test t
    where    one    = 1
    
    select    * from #test
    
    drop table #test



    • Proposed as answer by Melissa Suciadi Friday, September 18, 2009 4:04 AM
    • Marked as answer by Zongqing Li Thursday, September 24, 2009 1:55 AM
    Thursday, September 17, 2009 7:25 AM

All replies

  • create table #test
    (
        one        int,
        [second]    timestamp
    )
    
    insert into #test (one)
    select    1
    
    select    * from #test
    
    update    t
    set    one     = one + 1
    OUTPUT    deleted.second as previous, inserted.second as [current]
    from    #test t
    where    one    = 1
    
    select    * from #test
    
    drop table #test



    • Proposed as answer by Melissa Suciadi Friday, September 18, 2009 4:04 AM
    • Marked as answer by Zongqing Li Thursday, September 24, 2009 1:55 AM
    Thursday, September 17, 2009 7:25 AM
  • create table #test
    
    (
    
        one        int,
    
        [second]    timestamp
    
    )
    
    
    
    insert into #test (one)
    
    select    1
    
    
    
    select    * from #test
    
    
    
    update    t
    
    set    one     = one + 1
    
    OUTPUT    deleted.second as previous, inserted.second as [current]
    
    from    #test t
    
    where    one    = 1
    
    
    
    select    * from #test
    
    
    
    drop table #test
    
    




    I want to compare after update is done through a separate transcation(not through update transaction
    Thanks, Bharathi
    Thursday, September 17, 2009 7:51 AM
  • then you have to read the timestamp before update and then read it again after update
    KH Tan
    Thursday, September 17, 2009 8:07 AM