SqlServer的timestamp數(shù)據(jù)類型

字號:

--時間戳類型和bigint互相轉(zhuǎn)化示例:
    set nocount on
    --申明3個時間戳
    declare @timeFlag1 bigint
    declare @timeFlag2 bigint
    declare @timeFlag3 bigint
    --建立表,timestamp類型不需要字段名
    create table test(timestamp,a int)
    --插入1 記錄時間戳,@@dbts為數(shù)據(jù)庫時間戳
    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的記錄已經(jīng)不存在了
    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
    /**//*--測試結(jié)果
    timestamp     a
    0x000000000000B553 1
    timestamp     a
    timestamp     a
    0x000000000000B555 3
    */