哪位高人指點一下啦,問題是這樣的:
有一個資料表tb1,有一timestamp字段,我想根據這timestamp字段判斷記錄有沒有更新過,想用另一資料表tb2保存tb1中的ID和timestamp字段,下次用關聯查詢tb1中有哪些記錄已經變更,請問該如何做啊?
我找不到這方面的資料了。

解决方案 »

  1.   

    on tb1.id=tb2.id and tb1.timestamp < tb2.timestamp
    具体要大于还是小于,看你的要求了
      

  2.   


    --可以在資料表tb1上建立一个update的trigger,可以参考如下:Create trigger trigName on tb1
    for update
    as
     if Update([timestamp]) 
      begin
          Insert into tb2(id,[timestamp])
          Select id,[timestamp] from deleted
      end
    go
      

  3.   

    可以作为varbinary(8)来处理
      

  4.   

    請問樓上各位,請問樓上兄弟如何作為varbinary(8)處理呢?因為對timestamp不能轉成char或varchar。能給幾行代碼或實例嗎?非常謝謝。
      

  5.   

    可以作为varbinary(8)来处理
    把tb2的timestamp字段改为varbinary(8)类型
    做触发器
     Create trigger trigName on tb1
    for update
    as 
      begin
          Insert into tb2(id,varbinary(8)列)
          Select id,timestamp列 from deleted where id not in (select id from tb2)
          update tb2  set varbinary(8)列=timestamp列
               from tb2 ,deleted where deleted.id =tb2.id
      end
    go在查询时把 timestamp列转换为binary(8)  
    cast (ab as varbinary(8))
    做比较
      

  6.   

    cast (timestamp列 as varbinary(8))