哪位高人指點一下啦,問題是這樣的:
有一個資料表tb1,有一timestamp字段,我想根據這timestamp字段判斷記錄有沒有更新過,想用另一資料表tb2保存tb1中的ID和timestamp字段,下次用關聯查詢tb1中有哪些記錄已經變更,請問該如何做啊?
我找不到這方面的資料了。
有一個資料表tb1,有一timestamp字段,我想根據這timestamp字段判斷記錄有沒有更新過,想用另一資料表tb2保存tb1中的ID和timestamp字段,下次用關聯查詢tb1中有哪些記錄已經變更,請問該如何做啊?
我找不到這方面的資料了。
具体要大于还是小于,看你的要求了
--可以在資料表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
把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))
做比较