--時間戳類型和bigint互相轉化示例:by jinjazz
set nocount on
--申明3個時間戳
declare @timeFlag1 bigint
declare @timeFlag2 bigint
declare @timeFlag3 bigint
--建立表,timestamp類型不需要字段名
create table test(timestamp,a int)
--插入1 記錄時間戳,@@dbts為數據庫時間戳
insert into test select null,1
set @timeFlag1=cast(@@dbts as bigint)
--插入2 記錄時間戳
insert into test select null,2
set @timeFlag2=cast(@@dbts as bigint)
--更新3 記錄時間戳
update test set a=3 where a=2
set @timeFlag3=cast(@@dbts as bigint)
--時間戳1的記錄
select *from test where timestamp=cast(@timeFlag1 as varbinary(8))
--時間戳2的記錄已經不存在了
select *from test where timestamp=cast(@timeFlag2 as varbinary(8))
--時間戳3的記錄
select *from test where timestamp=cast(@timeFlag3 as varbinary(8))
--刪除表
drop table test
set nocount off
/**//*--測試結果
timestamp a
------------------ -----------
0x000000000000B553 1
timestamp a
------------------ -----------
timestamp a
------------------ -----------
0x000000000000B555 3
*/